Search Unity

Raycast in direction of objects heading

Discussion in 'Scripting' started by yesimarobot, Jun 2, 2010.

  1. yesimarobot

    yesimarobot

    Joined:
    Jun 19, 2009
    Posts:
    24
    I have a game object that rotates. When i raycast from this object the ray always heads in the same direction. How do I raycast based on the objects rotation?
     
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    You can use the transform's position and forward vector to do that:

    Code (csharp):
    1. Physics.Raycast(transform.position, transform.forward, ....)