[ODE] Player camera

William Denniss william.denniss at omegadelta.net
Thu Sep 16 13:40:57 MST 2004


On 16/09/2004, at 12:20 AM, Brian Clarkson wrote:

>
>  William
>
> Can you explain the attachment method. I understand all about geom
> transforms. I was interested
> in your description of the camera not following the car exactly. You 
> said it
> smoothed out fast
> small movements. I don't understand how that will happen without some 
> form
> of rubber band type
> attachment to the car.

Brian,

I compare the current position of the camera to the position of the 
target axis by axis.

If the difference between the two coordinates on a given axis is 
greater than the threshold constant, the camera moves in the direction 
of the target an amount which is the distance between the two objects 
divided by a "distance factor" constant, multiplied by a "multiplier" 
constant, with a minimum move of 0.25f.


Here's some code for the X axis:

		// chase cam by William Denniss
		float THRESHOLD = 3f
		float DISTANCE_FACTOR = 20f
		float MULTIPLIER = 0.25
		float MIN_MOVE = 0.15f

		if (cameraLocation.x - chaseTargetLocation.x > THRESHOLD) {
			float movement = (cameraLocation.x - chaseTargetLocation.x - 
THRESHOLD) / DISTANCE_FACTOR;
			movement *= MULTIPLIER;
			if (movement < MIN_MOVE) {
				movement = MIN_MOVE;
			}
			cameraLocation.x = cameraLocation.x - movement;
			
		} else if (chaseTargetLocation.x - cameraLocation.x > THRESHOLD) {
			float movement = (chaseTargetLocation.x - cameraLocation.x - 
THRESHOLD) / DISTANCE_FACTOR;
			movement *= MULTIPLIER;
			if (movement < MIN_MOVE) {
				movement = MIN_MOVE;
			}
			cameraLocation.x = cameraLocation.x + movement;
		}
		

So if the objects are 5 units apart on the X axis, the camera will move 
in the direction of the target:
(5 / 20) * 0.25
= 0.06
As this is less than the minimum move - it will actually move 0.15f 
(i.e. cover 3% of the distance).  For a very slow moving object this 
means the camera will not constantly be moving.

This camera will fall a fair way behind due to the large Distance 
factor, small multiplier and due to the large threshold will wait a bit 
before chasing.  I like this effect as if you are traveling fast you 
need to see further in front.  A tighter ChaseCam could use 0.5f and 5f 
respectively to stay closer behind.  Just tweak those values till you 
get what you want.

I find this works very well for me.  If anyone has some improvements to 
suggest, I'm happy to hear them :)

Cheers,

Will.
	
---
http://tankammo.com/



More information about the ODE mailing list