- Home /
Normal to Quaternion (relative to origin of hit object)
How do you convert a normal to a quaternion? Or, a vector3 in general?
Comment
Answer by Peter G · May 05, 2011 at 03:08 AM
Quaternion.LookRotation() It creates a rotation facing the vector.
This works - except the object is "off" by 90 degrees (parallel to surface, rather than normal). There appears no easy way to re-align axes on the object.
A normal on a flat surface has Y pointing up, and LookAt faces Z. To aim along Y, use YY = Quaternion.FromToRotation( Vector3.forward, Vector3.up);
and multiply by it after the LookAt (the order matters, so trans.rot = YY * trans.rot;
. I usually have to trial and error the combinations.