Well, I might help you with your problem that the camera doesn't turn with the player. The reason why is a mathematical one. Basically we have two points, each one defined by three values, X,Y, and Z. Therefore we have:

The Player: (pX | pY | pZ)
The camera: (cX | cY | cZ)

What we have to do now is to set the cX and cY values depending on the player's PAN-angle. Now you need a bit of knowledge about trigonometry. The sinus of the pan angle equals the camera's y-distance from the player divided by the overall-distance between the camera and the player. The cosinus of the pan-angle equals the camera's x-distance from the player divided by the overall-distance between the camera and the player.

So what is this all good for? With this in mind, the only value *you* have to choose is the overall-distance between camera and player, all other variables (cX and cY) can be calculated using the sin() and cos() functions. The cZ is easy to calculate, you just equalize it with the pZ and add any value you like, depending on how high the camera should be positioned.

The following code is the practical example of what I said before. camera_distance is the overall-distance between player and camera. Camera_height is a value you may choose yourself for the height of the camera.


camera.y = player.y - camera_distance * sin(player.pan);
camera.x = player.x - camera_distance * cos(player.pan);
camera.z = player.z + camera_height;

That code positions the camera behind the player. In order to make the camera look towards the player, just use

camera.pan = player.pan;

If you want you may also adjust the camera.tilt - value.


Greetz!


Alan

Last edited by Alan; 05/23/08 11:29.