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!