# How do I tell if my enemy can see my player?

Given a player and an enemy with position, and given the direction vector of each, how can I tell if one can "see" the other?

In other words, how do I test if one position with direction is in front or behind another position with direction?

For my purposes, 'in front of' means directly in front of, or 90 degrees to either side.

• Clearly the solution is to create another camera and re-render the scene from the enemy's point of view, then perform image recognition on the result for the player character. Commented Nov 20, 2014 at 20:54
• most simplistic answer award goes to... Commented Nov 20, 2014 at 23:33
• While Riking's comment was likely intended as a joke, this is the actual fair way to do it -- giving NPCs the same access to the game state that a player would have rather than allowing them to access the internal state of the game. Commented Nov 21, 2014 at 5:13
• @R.. Yes, but where do you draw the line? Taking this reasoning to its logical endpoint, NPC's eventually become sentient with the ability to play and think like a human being... at which point they would probably rationally decide to begin wallhacking again anyway :p Commented Nov 21, 2014 at 10:51
• @Thomas: In practice I think you can make some sort of compromise, approximating the level of information they would have as a player without going to the trouble of implementing it that way. Simple measures like correct testing for line of sight, limiting the ability to identify an object beyond a certain distance, etc. could go a long way. Commented Nov 21, 2014 at 14:22