Character rotation flips on x axis when facing 180 on Y Axis

As the title says, my player’s X rotation flips 180deg when the character rotates 180 on their Y axis. This also resets the Y rotation to 0.

This script is suppose to align the player’s relative forward vector with the surface normal of a wall.

transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.FromToRotation(-Vector3.forward, hit.normal), rotDamp);

I assume using -Vector3.forward as the from vector is the issue here, but I can’t figure out a fix or alternative. Any help would be greatly appreciated.


uses the shortest path in order to do any rotation and if you aren’t specifying an up direction, it’s less computation to move it as it is doing and therefore the shortest operation.

What you want is this:

Quaternion from = Quaternion.LookRotation(-Vector3.forward, Vector3.up);
Quaternion to = Quaternion.LookRotation(hit.normal, Vector3.up);
transform.rotation = Quaternion.Lerp(from, to, rotDamp);

If this solved your issue please upvote to help others find this solution faster. Thank you :]