Code: Select all
core::vector3df cameraPos = camera->getPosition();
core::vector3df targetPos = target->getPosition();
camera->setPosition(cameraPos+speed*core::vector3df((targetPos.X-cameraPos.X), (targetPos.Y-cameraPos.Y), (targetPos.Z-cameraPos.Z)));
if speed==1 the camera will move to the target in one frame, if speed<1 it will take 1/speed frames to move there, if speed>1 the camera will overshoot the target
note that overshooting can be a problem even if speed<1, so before moving the camera you should see if it's less than one frame away from hitting the target, and, if so, just move it right there
note that before I forgot to add the camera's current position to the change in position we were calculating.. that's probably what caused your weird problems
if you want the camera to move at a fixed speed (say a distance of x units per frame), we select the appropriate speed with:
speed = x/(targetPos.getDistanceFrom(cameraPos));