Character stand straight

I’ve implemented a spell casting system where my character always faces where he is casting. This some times makes his y rotation change when he’s casting upwards (flying enemy etc). I would like to reset his rotation to “stand straight” on the ground when I start moving again.

I’ve tried this:

transform.rotation = Quaternion.FromToRotation(transform.up, Vector3.up);

Believing this would make his current rotation align with the top of the world. Why is this not working and what would be the correct way to do this?

1 Answer

1

This will always make it straight, for best practice, add this to the end in Update() function.

Vector3 rotationVector = transform.rotation.eulerAngles;
rotationVector.x = 0;
rotationVector.z = 0;
transform.rotation = Quaternion.Euler(rotationVector);