Jump to content
  • Advertisement


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.

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

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 this post

Link to post
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%

m_fCameraDirection = rate*m_Camera.GetYRotation() - (1.0f-rate)*VehicleDirection;

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.


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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!