Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How to match a surface normal rotation

Discussion in 'Scripting' started by NathanWarden, Aug 22, 2008.

  1. NathanWarden

    NathanWarden

    Joined:
    Oct 4, 2005
    Posts:
    663
    Hi guys,

    My problem is not really matching a surface normal rotation, but matching it and actually keeping my object with the upside pointing up.

    I need to match a surface's rotation around the y axis and I don't want my object flipped upside down or anything like that. The surface is always a vertical surface like a wall.

    Any help would be appreciated.

    Here's the line of code I'm using and I've tried adding a few lines to correct the rotation, but to no avail:

    Code (csharp):
    1.  
    2.     transform.rotation = Quaternion.FromToRotation(Vector3.up, rayHit.normal);
    3.  

    Thanks,
    Nathan