[SOLVED] (Raycast) Stop enemy when Player not in line of sight

Before proceeding, please use the forum search feature at the top of the page to check if your question has already been answered.

How do I…

Hello.
I’m making a top down game and I want to make my enemies to chase the player when in their line of sight, and to stop chasing when not in line of sight.

What is the expected result

Using raycasting, I’m trying to make the enemies to chase the Player when it’s in their line of sight, and to stop, after a time, chasing the player when it’s not in line sight. The rays are cast from the Player for performance reasons.

What is the actual result

The enemy keeps chasing the Player even when it’s not in line of sight.

Related screenshots



chase

SOLVED

Solved it on my own.
I had to create a separate object group including the walls and the player, and cast a ray from the enemy when it’s in the “chasing” state and then check if it picks up the Player object.


image
chase2