Character Up Vector to Align with normal

So im making a game where the character’s gravity and rotation changes to align with the surface he is looking at when clicking and I have the gravity working, but the rotation is giving me some problems. I basically want the transform.up vector of the player to align with the normal of the surface that he is on while still being able to look left and right with the mouse. I have tried this, but I can’t get it to where the character can still rotate left and right along transform.up when setting it equal to the normal vector. Any Ideas on how to do this?

1 Answer

1

transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;

This works great thanks! but one thing i have noticed when rotating a full 180 degrees, it chooses to rotate around the x axis and I would rather it rotate the way the character is facing, would you know anyway to do this?

Thank you man, really appreciate this!

oh man, this just saved me hours of trouble shooting, thanks!!