- Home /
The question is answered, right answer was accepted
Smoothly Rotate object towards target?
Hi All,
I am making a top-down 2D racing game with AI cars. The tracks are irregular and I used a waypoint system to make the AI cars follow the track. This works fine, but I am having trouble making the cars turn towards the next waypoint smoothly.
The cars have constant speeds individually, but each car has its own constant speed, but the distances between the waypoints differ. I can make them turn but it is always sudden and jittery. I can't figure out a way to turn the car relative to the distance between the way points and its speed.
I tried moving the cars with both rigidbodies and translation. I tried getting the updated distance between the car and the next waypoint and divide it by the distance between the previous waypoint and next waypoint, using it as a step for RotateTowards, but still nothing.
Can anyone help, please?
Answer by tormentoarmagedoom · Sep 04, 2018 at 10:35 AM
Good day.
You should take a look at this functions:
https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
Look for some tutorials to learn how to use them if need more help after reading the manual.
Bye!