#### Archived

This topic is now archived and is closed to further replies.

# camera following the car

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

## Recommended Posts

Hi! I''m having problem with my camera following a car (in a third person way) The camera should follow the car from behind in a smooth kind of way, I mean like in most racing games the camera isn''t changed that much just because I turn left for a microsecond and then turn back. I started like this (but this doesn''t work very well, not at all actually) if (Vehicle->Direction != m_Camera.GetYRotation()) { m_fCameraDirection = m_Camera.GetYRotation() - Vehicle-Direction; if (fabs(m_fCameraDirection) > 0.5f) { if (m_fCameraDirection < 0) m_fCameraDirection+=0.1f; else m_fCameraDirection-=0.1f; } else m_fCameraDirection = Vehicle->Direction; } m_Camera.Point( Vehicle->XPos -(float)sin(m_fCameraDirection) * m_Zoom, Vehicle->YPos + 100.0f, Vehicle->ZPos -(float)cos(m_fCameraDirection) * m_Zoom, Vehicle->XPos, Vehicle->YPos + m_YMove, Vehicle->ZPos); any ideas?

##### Share on other sites
You may want to try an approach where the camera is always moving a percent closer to the direction of the car. It should be as simple as:

float rate = 0.1f // 10%

However, please keep in mind that you'll still need to watch out for a special situation (this applies to your previous code also)

Your car is pointed at 10 degrees and the camera is pointed at 350 degrees. You would LIKE for camera to take the short route around the circle which is only 20 degrees away. However, the equation above will cause it to take the long route (340 degrees). There are numerous ways to get around this, I've never found a "beautiful" way though. =P If anyone does, please let me know.

Brett

[edited by - Bretttido on September 16, 2002 3:07:24 PM]

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
14
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013643
×