Search Unity

"Vehicle tries to follow road" system

Discussion in 'Physics' started by Deleted User, Jun 16, 2015.

  1. Deleted User

    Deleted User

    Guest

    I have a skateboard game and I am trying to make the steering controls easier. One idea is to have the skateboard tend to follow the direction of the road when the player is not tapping the controls.

    I have a decent system that works on straight roads by adding small amounts of torque to the skateboard to align it to the road direction.. it seems to do the trick of making steering easier.

    Now I am trying to extend it to curvy roads. My problem is that I need a way to find the forward direction of the road at the point the skateboard is on. I've developed the idea below, but I'm wondering if anyone has ever done something similar, or has a better idea.

    Illustration:
    AutoStraightenerIdeas.jpg

    Basically, the idea above is that I manually place "markers" (in blue) along the road that face the forward direction of the road. Then I attach a large sphere collider to the skateboard. At each frame I find the markers that are inside the sphere collider, then loop through them to find the one closest to the skateboard. Finally, I find the angle between the forward direction of the marker and the forward direction of the skateboard to create a multiplier for the adjusting torque on the skateboard.

    Looping through the markers inside the sphere collider seems inefficient, but I can't think of a better way. Anybody have a better idea?

    Thanks in advance!