Search Unity

How to make raycast do not ignore terrain when the start point is below terrain?

Discussion in 'Physics' started by Xhitman, Jul 6, 2018.

  1. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    My case is : I have some turrets underground( y position <0, terrain y position = 0), I don't want them to fire anything on terrain. But terrain cannot block raycast when start point is below.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    One quick fix is to reverse your raycast, so that instead of raycasting from turret to target, you raycast from target to turret. That way you'll hit the terrain.
     
  3. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    Thx, I think I will add double raycast check on both direction, so the turrets above terrain can use the same check loop.