3rd person camera spring

Started by
11 comments, last by Staffan E 18 years, 7 months ago
All racing games use springs on cameras don't they? But the funny thing is, say when your acceleration is longitudinal, the cameras pretty much stick to the car. But they have a smooth slow damped motion when turning. My camera lags behind too much if I try to get a nice visual effect while turning. Any hints?
Advertisement
Why not use different dampenings for forward/backward and turning motion?
That is they way I have done it, and it behaved like in most games.
Thanks for writing in, gulgi! Yeah, I can incorporate different dampings, but how do I make it specific to longitudinal or rotatory motion? As I have it now, the ultimate position of the camera depends on only one external factor - the position of the car. So how does the camera differentiate whether it is turning or moving straight?
Heellloooo? Anybody there?
Hey, chill out. You're lucky you even got a reply. Half the time I don't even get a reply to my posts. How is the car turning? Using an angle? Use this angle to determine the new camera position, but instead of instantly changing the camera's placement to that position, add a number to the position until it's moved there. This would give you the spring effect.
Hey Ignisdeus, even if I'm not getting replies, I'm loyal to these formus. I resent your comments, yes sir! And I've got the spring effect in place actually, I was thinking of how to limit the spring effect to turning motion. I have an idea - to clamp the distance of the camera from the car. Does anyone think that will do the needful? Yes, even you IgnisDeus ...
Let's keep a friendly tone in here shall we.

These are some offhand calculations I made just now. I don't know if they will fit into your model but here goes.

This damping model is based on that you have an angle (in the plane) for the car denoted θcar and a corresponding angle for the camera denoted θcamera. To make the camera move from it's initial angle θcamera to the angle θcar parallel to the car you could interpolate between the two angles to get a new intermediate angle θnew for the camera, using

θnew = θcamera + (θcar - θcamera) * F(Δt)

where F(Δt) is some fuction of the time duration Δt and acts as interpolation factor. For this particular damping model

F(Δt) = 1 - e-k * Δt

where k is defined by

k = (ln 2) / Δt1/2.

In this definition for k, Δt1/2 is the average time you want for the camera to turn half the way to the car's direction. You can pick any value for Δt1/2. The final formula is

θnew = θcamera + (θcar - θcamera)(1 - e-k * Δt).

Use this formula every frame with Δt as the duration since the last frame to calculate the new angle for the camera. I think it should work quite well. I haven't tried it myself though[smile]. Tell me if you do.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Heh. I just realized that the formula for θnew in my previous post can be greatly simplified using powers of two instead of powers of e, eliminating the need for k altogether. The formula becomes

θnew = θcamera + (θcar - θcamera)(1 - 2-Δt / Δt1/2).

Δt1/2 is still a constant value that you pick yourself.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Don't worry anyone, everything's fine with me and ignisdeus! [smile] I don't know what made me write that ... any way, no hard feelings Ignisdeus ... and I know how you feel - it's frustrating to not get answered, but this place has helped me SO much that I think you should give it a fair chance too.

staaf, I have a spring code, like the one you described, only it interpolates position, not angle. So if I implement it your way, I have to ... let's see ... find out the new angle, then subtract a set scalar (dist betn camera and car) in the direction of theta, and that will be the position of the camera! I'll give it a try and post back.
staaf, I got your code working, but I have taken the angles as negative when snticlockwise (0 to 180 degrees) and positive when clockwise. The problem occurs when the car's angle jumps from -179 to say 179. Do you have any suggestions?

This topic is closed to new replies.

Advertisement