Camera moving towards an object

Started by Yerst, July 19, 2013, 11:23:33 PM

Previous topic - Next topic

Yerst

Hey!
I try to move my camera to an object with this line:
world.getCamera().moveCamera(planet.getCenter(), speed);
Shouldn't the camera stop moving in the center?
The Camera actually moves through the center and on the other side out.
I watched the distance between the camera and the center of the object, and the center is on the right place.

EgonOlsen

You are mixing spaces here. What you want to feed into this method is the camera's translation in world space. What you do feed it is the center of an object in object space. That this makes the object move towards the center of your object is just a coincidence. What you actually want is to calculate the direction vector between the camera and what Object3D.getTransformedCenter() returns and move the camera by a fraction of it until you reach the center (or are very close).

Yerst

Ok, but how do i calculate the direction vector between the camera and Object3D.getTransformedCenter()?
I thought this would do it, but i was wrong:
world.getCamera().moveCamera(world.getCamera().getPosition().calcAdd(planet.getTransformedCenter()), speed);

EgonOlsen

Just subtract the camera's position from the transformed center. It's basic vector math: