Two raycasts (front-left and front-right) decide when to turn left or right.
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…
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.