I want to make another advance NPC behavior which allows the enemy to be alerted when sighted the player or shooting at them, taking cover from the player, and coming out of the cover to shoot back a couple of bullets. I wonder if it’s possible to use raycasting? to detect the player.
Yes, you can probably use raycasting to detect the player.
Or more easily, you can make a sprite representing the field of vision, and use a collision condition.
What about the other part?
You will need to develop your own logic for “coming out of cover” since that isn’t a concept in any of the behaviors, but I believe the “pathfinding with AI” example included in the main example list shows how you can use raycasting to give enemies a cone of vision/detect line of sight to the player.
So, I took the sprite approach. Now, I want to make the enemy alerted when they see me or get shot.
You need to explain what you’re stuck on exactly, we have no telepathy superpowers.
So, I use Tween to smoothly move the enemy NPC to the nearest cover when the player is in contact with the line of sight. Here’s a screeshot:
What I want is to delete the line of sight, mark the player to be attacked, and make the enemy peek out of the cover to shoot the player.
And what are you stuck on?
You seem to know how to change an instance variable (mark a player), and I’m sure you know how to delete an object (although disabling it with a variable might be easier).
Regarding “peek out and shoot”, you need to word clearly what should happen, and you’ll probably know how to proceed.