Camera behind a moving object (tomb raider style)

Blitz3D Forums/Blitz3D Programming/Camera behind a moving object (tomb raider style)

If your camera's not moving using Quaternions it should.

And if it's not moving with a constant angular velocity, it should. After all, you don't want your game running at different speeds on different systems.

When you use stuff like aligntovector, you need to be careful, unless of course you're using render tweening to avoid having to worry about things moving at different speeds on different ssytems. But if you're not, then you'd have to calculate the difference in the angles and then use the time passed in a frame to move at a constant angular rate. Though you can smooth things out by adding a cosine to your angular rate so that things slow down as they approach the end values.

It's not an easy task, but it's not too hard either. I'd first go to the code archives, and find the Quaternion library that is there. Then stick that in your code, put in your camera's orientation, and the destination orienatation into the euler to quaternion function, and then interpolate to a point between the two quaternions using the quaternion SLERP function, and then convert back to euler rotations so you can adjust the camera.

You can easily make sure you move at a constant angular rate by doing a dot product between the two orientations, and then you'll know how much your two orientations point in different directions. Then when you know you're 180 degrees apart, and you want to move 90 degrees per second, you can calculate the time the frame took, multiply that by 90, and then divide 180 by that, which will give you a number which should be between 0 and 1 which is what you input into the SLERP function to tell it at what point you want the interpolation to be between the two orientations.

Btw, Tomb Raider uses Quaternions for it's camera movements. It uses them because you get the most realistic and smooth interpolation with them.