Skip to main content
GameDev.net gamedev.net
🔒 Locked

camera movement suggestions?

Started by code_evo Feb 1, 2004 at 7:34 AM 4 replies 450+ views
Original Post
code_evo
code_evo
Ok so i've finally completed my physics and collision detection for my racing game, although they arent amazing i'm pretty satisfied with my work and i have limited time so I cant work on them anymore. Anyways, now i'm on to the camera class. Basically right now i'm placing the camera behind the car (well i have 4 views but this is the view that is giving me headaches) and aiming it infront of the car following the velocity vector. This gives a nice swinging motion, if you turn sharp and slide the rear-end out, the camera doesnt swing right away and then wraps around really nicely. edit: i place the camera behind the car (position - velocity vector) and points towards the car position, thats what produces the nice swinging effect However, because i'm simply following the velocity I have many problems when car changes direction, stops, crashes etc. Changing direction is the biggest cause for concern. So I'd like to implement a more refined camera, but i'm not sure what approach to take. Matrices, quaternions, just simply trig/vector stuff, i'm not sure what will give me the best results and I dont want to try all of them. I"m looking for standard car camera movement, a la gran turismo etc. Thanks for any suggestions, /jeff [edited by - code_evo on February 1, 2004 9:29:58 AM]
Hamster
Hamster
This is just a thought off the top of my head, so it may not work, but how about trying a spring system?

I would suggest having an imaginary point, perhaps a little above the car which the camera takes as being the anchor for one end of the spring, the other being the camera. This would mean that as the car speeds up the camera accelerates after it, and might give a better impression of speed, although admittedly it could get irritating if the spring was too loose or the mass of the camera too great. The camera would look along the direction of the spring.

I realise that this doesn''t go very far towards solving your original problem, in which case I''d introduce an angular spring. As the spring direction deviates more and more from the ideal, a greater and greater force is applied to try and get it back in line.

If the two were coupled it might be possible to get something like what you''re after, with a little tweaking.

The maths might get a little complicated. There are probably easier ways of implementing the angular spring, but one that comes to mind is the shortest arc quaternion, which takes to direction vectors and produces the quaternion equivalent to the shortest possible rotation from one to the other.

This could easily be a horrible idea, and would probably take a while to implement, but I''d be interested to hear what other people think. Probably best not to try anything until you hear from someone who has a clue :-)
code_evo
code_evo

I appreciate it, but unfortunetly I''m a bit short on time and I think that solution would be too robust for what I need.

I must say also that my ground is flat, always, so I dont need to rotate around more than 1 axis. Also, the camera moving backwards when accelerating etc is already taken care of. I just need to eliminate my current problem. I''m happy with my current movement, its quite smooth when its working.
code_evo
code_evo

Well after a day of reading, I think I''ll try using quaternions for my camera, and I can achieve swinging with SLERP.

I''m not quite confortable with slerp yet, like how to change the speed, set cutoffs all that jazz. maybe i''m not even visualizing it properly.

Ah well, i''ll post back if I have any problems.
Paradigm Shifter
Paradigm Shifter
An easy and nice-looking solution is to use a camera on a stick centered on the car, but damp the camera so that it moves say 7/8ths of the way from where it last was to where it wants to be.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
ajas95
ajas95
It sounds like you want to damp your camera motion some. Say, from its current position have it take half a second to get to where it wants to go, this means that its velocity should always be 4 times how far it needs to go (2 * 1/0.5secs).

vToCam = (camera - position).normalize();
vCamDesired = (position - velocity).normalize();

// Direction we''ll have to travel.
vToDesired = (vCamDesired - vToCam).normalize();

// How far away on the unit circle do we have to go [0..1]
fAngleNormalized = acos(vToCam.Dot(vCamDesired)) / PI;

// calculate a desired angular change (divided by PI)
fCatchUpWeight = max(1.0f, 4.0f * fAngleNormalized * timeStep);

// Linearly Interpolate ... a rotation would be more accurate, but why bother?

vFinalCameraDirection = (vToCam + vToDesired * fCatchUpWeight).normalize();

camera = (position + vFinalCameraDirection * camera_follow_dist;

Another thing you could do is scale the catch-up weight by the speed of the vehicle, so that it swings faster during driving, but slower while almost stopped (crashed, or spinning in wipeout).

fCatchUpWeight *= car_speed / 20.0f;

note that vToDesired is undefined if vToCam and vCamDesired are in exactly opposite directions.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.