• Advertisement
Sign in to follow this  

Following a car with camera like in Need for speed

This topic is 4688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I have a little problem writing my camera class. I'd like to follow the car from behind like in popular racing games. I have the matrix of the chassis. How to calculate the ViewMatrix in D3D? Thanks in advance. arpi23

Share this post


Link to post
Share on other sites
Advertisement
To start out, set the camera to the position of the car looking forward. Translate back and up. This is is the 'ideal' position of the camera when the car is stopped.

Unfortunatly, the ideal position looks awful when the car is moving, since it jumps around a lot.

Assuming you are using a physics engine, put an object at that point, give it some intertia, and a spring to move it back to that point. You'll need to do a lot of tweaking and add a few constraints to keep it pointing the right direction and keep it from drifing too far away.

If you aren't using a physics engine, implement a springy-effect by keeping track of the previous position and orientation, as well as the previous movement deltas. Adjust the deltas based on the distance between the ideal and the current position. Add constraints on the maximum distance from the ideal for both position and orientation, as well as a motion decay (probably based on ratio of ideal:current).

You'll need to do additional tweaking, such as turning more than the car so you can see more toward the direction you are turning. You'll also want to move the camera based on other objects in your world so you don't end up occluding most of your scene with a stray object.

The code for that is going to depend on your implementation. Hope that helps.

Frob.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement