smooth rotation unity 1

smooth rotation unity

Vector3 targetRotation = path[i].transform.position - transform.position;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(targetRotation), 4f * Time.deltaTime);
//LookRotation points the positive 'Z' side of an object in a specified direction
//FromToRotation creates a rotation that from one direction to another direction

Here is what the above code is Doing:
1. We’re getting the position of the next waypoint in the path.
2. We’re getting the direction from the current position to the next waypoint.
3. We’re rotating the object to look at the next waypoint.

Similar Posts