Why wont my raycast work?

Why is my raycast for my topdown game not working. my enemy never attacks me also the line isnt being drawn. the number of objects picked is always 1. i dont know why.


If the ray doesn’t hit any “solids”, the condition is FALSE and therefore nothing after it will happen.

What you could do instead is always change the “found” variable to TRUE before the raycast. Then, if the raycast is successful (hits a solid), change found to FALSE.

1 Like

it doesnt work, did i do it wrong?
found is always true and the number of solids picked is always 1

i figured it out, this seems to work

That is essentially what I suggested, although there is no need to do the raycast twice. You could get the same result with better performance this way:

(empty condition)         |        change the variable found to TRUE
----------------------------------------------------------------------
cast a ray against solid  |        change the variable found to FALSE

If an object is detected by the raycast, it will pick the nearest object or farthest if the raycast condition is inverted. It will only every pick 1 object maximum. If there aren’t any objects then the action and any subevents won’t get triggered.