- Home /
Rotating to match normal: Quaternion.FromToRotation(player.up, hit.normal)
Hello,
I'm using this to rotate according to the slope that the player is on:
_handRoot.rotation = Quaternion.Lerp(_handRoot.rotation, _handRoot.rotation * Quaternion.FromToRotation(_handRoot.up, hit.normal), Time.deltaTime * 2f);
This works if I go up a slope. If I turn around and go back down the same slope, the player turns upwards, away from the slope, and flies off into the sky....
Any clues towards the fix would be greatly appreciated.
Answer by lpincombe · Jul 18, 2020 at 03:15 PM
Here was the solution, for anyone looking (this should be in a coroutine or in update). (_handRoot here is my player).
Vector3 forward = Vector3.Cross(-hit.normal, _handRoot.right);
_handRoot.rotation = Quaternion.Lerp(_handRoot.rotation, Quaternion.LookRotation(forward), Time.deltaTime * 2f);
Your answer
Follow this Question
Related Questions
Child transforms screwed up by parent's rotations 1 Answer
Why does the raycast hit only objects/faces of a certain rotation? 1 Answer
Setting rotation of instantiated object to that of a raycast? 1 Answer
How to get Raycast surface normal to align particle system? 1 Answer
How to match rotation of Object to a face on another Object 1 Answer