Smoothly transitioning between two anglesUnity

I have this code below that sets the player Rigidbody to the same rotation as the checkpoint it just hit. This is done so that the player will automatically move around a curve in a racing game without them actually having to do the turning.

private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Checkpoint")
        {
            checkRot = other.attachedRigidbody.transform.localEulerAngles.y; //gets the Y rotation of the next position as a float
            rb.transform.eulerAngles = new Vector3(rb.transform.eulerAngles.x, checkRot, rb.transform.eulerAngles.z);
        }
    }

The code works for moving around the curve. However, it is very choppy as you usually move in about 10-degree increments.

I’m wondering if anyone has any ideas on making this transition smoother? I tried to do something with slowly changing the angle as you move towards the next checkpoint based on how far away the player is but that doesn’t exactly work as it causes the player to drift out. Any help/ideas would be greatly appreciated!

You can Lerp (or Slerp) smoothly between two rotations the same way you do positions.

Whatever you are using to position yourself between two waypoint positions, use that same fractional distance to drive the rotation.

You could also probably use a tweening package (like ITween or DOTween) to do it.

Also, generally never manipulate eulerAngles. Here’s why:

https://starmanta.gitbooks.io/unitytipsredux/content/second-question.html

1 Like

Thank you so much for your help. I’ll try to implement both things in a bit.