Camera physics much like Dirt 3 help

Hello,
I am wondering before I sit down and code a whole script for my camera, if there is any free camera script that gives the feel of physical movement like that of Collin Mcrae Dirt 3?

I am wanting an almost fixed camera position in 3rd person looking at the car, that follows the car and acts a lot like a GoPro on a pole behind the car.

I can write java if there are any suggestions that would be much obliged!

Daniel

here is an example : http://www.youtube.com/watch?v=_nuxWmpvHSs

the one they use looks pretty static, like, it’s allways behind the car, but it detects if the car is turning, if the car is turning alot it conpensates a bit in the opposite direction so it doesn’t show the same image of the car all the time, same probably works for jumping.

This looks like they’re simply constantly making the camera move and rotate towards a “target” position and rotation behind the car. The speed at which they make the camera move makes it “lag” a little behind the actual target, which makes it possible for the camera to be in slightly different positions behind the car.

What I would do is define a target Transform relative to your car (which is fixed to the car), and then in (for example) LateUpdate() on your Camera you’d do something like:

var : float LerpFactor = 0.5;
this.transform.position = Vector3.Lerp(this.transform.position, target.transform.position, LerpFactor);
this.transform.rotation = Quaternion.Lerp(this.transform.rotation, target.transform.rotation, LerpFactor);

Note: I haven’t written any JavaScript in a while so there may be some C#-ish syntax in there :wink:

You can modify LerpFactor to alter the “lagginess” of the camera. A factor of 1.0 would make it instantly snap to the target Transform every frame, a factor of 0.0 would not move it at all. Somewhere between 0.0 and 1.0 is a value that should be appropriate for you!

@Rycul Thank you! :smile: Now I would like to add a “spring” and a “Damper” so the camera reacts a lot like you would if you were sitting in a car thats bouncing around. (Like the camera bounces with some dampening so its a controlled effect) :stuck_out_tongue:

You might get a decent enough result for that ‘bouncing’ effect if you somehow detected when large enough ‘hits’ occur. Then once such a ‘hit’ occurs, you change your lerp factor to something greater than 1.0 so that it will overshoot its target when interpolating (Giving the ‘bouncing’ effect). Then, over the course of a certain amount of time (1.5 seconds maybe?), you gradually decrease the lerpfactor back to the ‘ideal’ value. You could even use an AnimationCurve object in your script that would describe this change from > 1.0 to your ideal factor to make it easy to alter and precisely control the dampening feeling.

Note that this is just a theoretical approach and I haven’t actually tried to implement that, but I think that should give you a pretty decent effect!