- Home /
RaycastHit.normal and Orientation to a Path
Hi,
I'm using iTween to move an object along a path, using RaycastHit.point to make sure the object tracks the Y height of the mesh object it's moving over and RaycastHit.normal to orient the object according to the surface beneath it.
The intended effect of all these is to produce the movement of a bug crawling over an uneven surface while following a path.
I'm very nearly there, but, when I set object.transform.up = RaycastHit.normal it also points the object in one direction, overriding the code I have to have the object face along the path (using LookAt elsewhere).
So, my question is, how can I use normal to have the bug orient to the surface beneath it, but still have it face along a path?
Answer by Jessy · Apr 05, 2011 at 01:21 PM
http://unity3d.com/support/documentation/ScriptReference/Quaternion.FromToRotation.html
if (Physics.Raycast(transform.position, -Vector3.up, out raycastHit))
transform.rotation = Quaternion.FromToRotation(transform.up, raycastHit.normal)
* transform.rotation;