Skip to content

Instantly share code, notes, and snippets.

@dcrystalj
Created May 28, 2014 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcrystalj/0411d7c9e9ea2d64ebb4 to your computer and use it in GitHub Desktop.
Save dcrystalj/0411d7c9e9ea2d64ebb4 to your computer and use it in GitHub Desktop.
unity
RaycastHit rcHit = new RaycastHit();
Ray bottom = new Ray(this.transform.position,Vector3.down);
if (Physics.Raycast(bottom,out rcHit,20))
{
double posy = transform.position.y;
//with this you rotate object to adjust with terrain
transform.rotation = Quaternion.Slerp(
transform.rotation,
Quaternion.FromToRotation(Vector3.up*Time.deltaTime, rcHit.normal),
Time.deltaTime
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment