I have camera a that is actively following an object (a plane) from behind. This object can accelerate or decelerate.
I would like to have a camera offset when I move the plane, so it doesn't look so static.
I have done this with the following code:
float cameraOffset = 0.05 * elapsed_time * 100;
Vector3 previousEye = camera->eye;
Vector3 newEye = ship->model * Vector3(0, 10, -5);
Vector3 eye = previousEye * (1 - cameraOffset) + newEye * cameraOffset;
Vector3 previousCenter = camera->center;
Vector3 newCenter = ship->model * Vector3(0, 0, 10);
Vector3 center = previousCenter * (1 - cameraOffset) + newCenter * cameraOffset;
Vector3 up = ship->model.rotateVector(Vector3(0, 1, 0));
camera->lookAt(eye, center, up);
previousModel = ship->model;
It works fine, except that when I increase the object's speed, the camera barely follows it. This is of course logical; my code is supposed to make it difficult for the camera to follow the plane.
However, I would like to have a lateral camera offset and also to keep following the plane from a relatively short distance.
Any hint on how to achieve this is appreciated.