raycasting race game question:)

Hello, what Im trying to do is:

  1. Two raycasts (front-left and front-right) decide when to turn left or right.
  2. Now (diff means difference: frontLeft - frontRight, so we know were on the road are we)
        if (diff > 11)
            {
                slowDown();
                gameObject.SendMessage("RemoteSteer", -1);
            }

            
            if (diff < 9)
            {
                slowDown();
                gameObject.SendMessage("RemoteSteer", 1);
            }

The car simply turns left(or right) 4-5 times per second, because its IF condition, so it tries to stay as close as possible. Anyone got idea how to do that, so enemy AI would turn once and then go straight forward? I mean ugly wheel’s animation…

What’s happening now? Is the car swerving back and forth? Maybe make the amount of steering dependent on how far to the left/right you are. ie:

gameObject.SendMessage(“RemoteSteer”,(10 - diff)/10f);

For example: between LeftForward and RightForward there is 9 meteres of difference.

If the car goes a bit farer and there will be 9,01meters - it will turn left for 0.01s to be 9 meters away. And again,
and again,
and again.

I think it should wait untill there will be 10 meters and straight up when 8 meters, but I have problem to figure out how to do that in c#

diff = Mathf.FloorToInt(diff);

I had posted in another person’s thread concerning exactly how to calculate the turn and rotation of the wheels to a certain point. Where I have developed it a lot further, you may find what I had there useful. Basically it calculates the difference in rotation that the vehicle is headed and measures it against the angle that it wants to go. It takes into account max steering angles and doesn’t over steer so your not weaving back and forth to the location.

http://forum.unity3d.com/threads/74799-Turning-a-car-manually

Nah, that can be helpful, thanks, but still my script fails. What Im excaly trying to do is:

  1. Between left and right side is 9 meters difference, so the car moves forward.
  2. Now, there is 9.01meters difference and there comes turn left, just for 0.1seconds.
  3. Point 2 happens 3-4 times each second.

What I need to do is to let car turn ONCE. So let the car go 11 or 12 meters away and then turn left until there is 9 meters. But still fails.