Smoothly Rotate Character Y to Camera Y

Hi again. I’m now trying to make my character’s y rot to lerp to the same value as the camera’s y rot. This way the character will face the same direction the Camera is, at least that’s what I expect to happen. This is the code I’m using:

    private void RotateToCamFunc()
        if (IsMoving())
            float camY = Camera.transform.eulerAngles.y;
            float newY = Mathf.Lerp(transform.eulerAngles.y, camY, camBasedPlayerRotationLerp);
            transform.eulerAngles = new Vector3(transform.eulerAngles.x, newY, transform.eulerAngles.z);

Unfortunately, it’s pretty glitchy. The character will just randomly glitch while turning. And when I believe the camera goes from 359 to 0, the Lerp craps itself and does a full 360 degree turn the opposite way.

Any Idea how I could fix this, or a better solution to the problem altogether?

Always be careful when messing with euler angles, make sure you are only doing as little as possible with them. In general it is bad practice to read, modify, write euler angles because it can result in exactly the kinds of problems you are describing. Instead, use quaternion functions whenever possible.

private void Update()
        Quaternion targetRot = Quaternion.Euler(0, cam.transform.eulerAngles.y, 0);
        transform.rotation = Quaternion.Slerp(transform.rotation, targetRot, slerpVal);

Oh, thanks! I had tried Quaternion.Lerp before but it was glitchy too, so I decided to go back to eulers. Looks like Slerp was the solution all along. Thanks again!