Search Unity

Raycasting - 1 unit up y axis - but its drawing no the ground?

Discussion in 'Scripting' started by Homicide, Feb 15, 2018.

  1. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    Hi guys. Im wondering if anyone can shed me some light on why this is happening.

    Code (CSharp):
    1.             Vector3 direction = c.t.position - transform.position;
    2.             Debug.DrawRay(transform.position, direction, Color.red);
    3.             if(Physics.Raycast(transform.position, direction, out hit, castDistance)){
    4.                 if (hit.collider.transform == c.t) {
    5.                     Debug.DrawRay(transform.position, direction, Color.red);
    6.                 }
    7.             }
    its drawing in the correct direction, but both object transforms are up 1 unit on the y axis, and yet, the line is being drawn on the 0 unit. the floor. o_O
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    The only thing I can think of is you have an offset on your box collider.
     
  3. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    Can you show the object in the inspector that this is happening too?