Godot 2D Top Down range finder respects solids

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Halflove

Hey there,

So I’ve been messing around with godot trying to learn as much about the engine functionality as possible before I try making a full-fledged game, and I’m a bit stumped on how to get my enemy AI range finder to respect solid walls.

Here is a gyazo video of what is currently happening: https://i.gyazo.com/7414d819989b27af6a818a480ca7976f.mp4

Ideally, I would not like the enemy to detect players through walls.

The way I am currently making this range finder is by using a circular area2d and detecting if the player enters that region. I’m open to any better ways of accomplishing this as well. https://i.gyazo.com/62ace6b3b28dd82db4eeacca6f42b955.png

Thanks for your help in advance!

:bust_in_silhouette: Reply From: codelyok13
  1. Detect player in region
  2. Fire Raycast at player to see if there are any obstructions
  3. If an obstruction is there, continue else if it hits the player do something