How to spot enemy a player?

I would like to when enemy patrols the area, enemy has to spot player and player has to avoid enemy for not taking damage.
How can I do it?

There’s so many way … why don’t you try google

Easiest way to start would to be to check if player is within a circle of enemy center point. If that is true then you can check for obstruction inbetween the two points.

/*
using 2 dimensions. So if this is 3D then y would be z and I'm not going to tackle if things are layered on top of eachother.
player.x and player.y are the center point of the player.
enemy.x and enemy.y are the center point of the enemy.
radius is the distance from the center of the enemy to the edge of detection.
*/
//calculate distance.
float distance = (player.x - enemy.x) * (player.x - enemy.x) + (player.y - enemy.y) * (player.y - enemy.y);
//check if player in range.
if (distance <= radius * radius)
{
   //player detected
}

I tried .Then I asked this forum.

Thanks sir.