Centering the camera on an object

I’m trying to center the camera on an object when the object is clicked. Browsing trough the documentation I found two functions getScreenPosition and getScreenVect. Here’s how I’m trying to use them now:

screenPos = camera.getScreenPosition(obj)
newpos = camera.getScreenVect(screenPos[0], screenPos[1])
camera.position[0] += newpos[0]
camera.position[1] += newpos[1]
camera.position[2] += newpos[2]

This however doesn’t seem to work…

Am I at least using the right functions or did I get this completely wrong?

Use trackTo sensor. Check the blend file.

track_to_test.blend (141 KB)

Thanks REiKo Rhoemer, it didn’t pass my mind there could an actuator I could use for something like this :).

I am glad to help :slight_smile: