- Home /
Quaternions- how to leave out Y rotations...
I don't know how correctly leave out the y factor in this code concept
if(Physics.Raycast(raydown, hit, RayDist , 1<<9)) transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
the code itself correctly aligns the object with the ground's normal, but restricts the object to always to look forward on its y, which blocks my ability to turn or steer with keyboard commands. Is there a way to leave the y rotation out of this equation? Thank you
Answer by whydoidoit · Sep 19, 2012 at 11:00 PM
I think what you really want to do is multiply out the FromToRotation - I guess it would look like this:
transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
(Or that multiplication might be the other way around)
You want to use transform.up rather than Vector3.up as this object may not be pointing straight up (which is important when applying it like this).
I know this is probably just a simple snip of code to you, but you've just helped me with an important issue I've been struggling with forever. I've really needed a solution, and you've helped me more than I can express here. If I could kiss you, I would. Thank you so much, I appreciate your help.
list LOVE ! dudes I totally want to kiss everyone as well. Awesome!
great question with an epic answer
Hey no problem - I clearly remember my eureka moment on Quaternions :)