Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Raycast always down, whatever the position of the emitter.

Discussion in 'Scripting' started by LeLoicLe, Oct 6, 2020.

  1. LeLoicLe

    LeLoicLe

    Joined:
    May 27, 2020
    Posts:
    25
    HI
    I would like to make a raycast from an object that, whatever its position/rotation, it always point down to hit a ground.
    So I put as the first parameter transform.position, but as the second one? I dont know.
    When i use -transform.down it points at local, if the rotation of the object change the raycast will change too.
    Also tried with Vector3.Down.
    What should I put?
    Thank you, hope I am clear. :)
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Vector3.down is correct.
     
    LeLoicLe and adamgolden like this.
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    same as PraetorBlue: just Vector3.down to make it work in absolute world coordinates, not transform.down as that will take into account the rotation of the transform (accessible from the gameobject where you're script is at).
     
    LeLoicLe likes this.
  4. LeLoicLe

    LeLoicLe

    Joined:
    May 27, 2020
    Posts:
    25
    OK, I saw where my problem was.
    The GameObject1 that has the script is in another Gameobject2 which is another GameObject3.
    And in first parameter I gave the Transform of the Gameobject3...
    So i change, put the Transform of GameObject1, put Vector3.Down, now it works.
    Thanks guys! :)