Line of sight and enemy AI
I am making a top-down stealth game. I am trying to create a system by which the enemy will spot the player character if they are in line-of-sight.
I tried to make a system before by which each enemy fired out a line of invisible particles in the direction they were facing that couldn't pass through walls. If the particle collided with the player, an alert was triggered. However there were some weird glitches with this system, and the particles also caused considerable lag.
Does anyone have any ideas of how to make a good line-of-sight detection system? There's pretty much 3 criteria that need to be met:
-Enemy will not detect the player through walls.
-The enemy can only see the player if the player character is in front of them, not behind them.
-No noticeable performance impacts or bugs.
This issue has been causing me problems for a while now and it really is essential for my project.
Any suggestions will be greatly appreciated. Thanks in advance.
Comments
I believe it was @RThurman who created a fantastic demo file for line of sight. I think it's located in the Spare Code thread (search for it).
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
make a new actor that will be the sight and in your player put if actor collides with the sight, then destroy actor (or change scene depending if you have a game over).
oh and if you dont want the sight to go through walls make a new integer and set it to 0, and in your sight actor put if actor collides with the wall change the integer to 1, and put if attribute "" is 1, destroy actor. And then put a sight spawn in front of the enemy and say if attribute "" is 0, spawn actor sight. (if you make the enemeys move WITH the sights i cant help u :P)