I am currently working on a game in flash (with AS3), and I ran into a weird issue with the line of sight of the enemies. It's easier to explain with a picture. Blue = walls. Green = enemy. Red = area the enemy can't see the player.

This is the codes:

var playerVisible:Boolean = true; var angleRadian = Math.atan2(_player.y - _enemy[i].y, _player.x - _enemy[i].x); var angleDegree = angleRadian * 180 / Math.PI; var enemyDistancex:Number = _player.x - _enemy[i].x; var enemyDistancey:Number = _player.y - _enemy[i].y; if(enemyDistancex < 0) enemyDistancex *= -1; if(enemyDistancey < 0) enemyDistancey *= -1; var enemyDistance:Number = Math.sqrt((enemyDistancex * enemyDistancex) + (enemyDistancey * enemyDistancey)); while(enemyDistance > 0 && playerVisible) { if(_walls.hitTestPoint(_enemy[i].x - (Math.sin(angleDegree * (Math.PI / 180)) * enemyDistance), _enemy[i].y - (Math.cos(angleDegree * (Math.PI / 180) * -1) * enemyDistance), true)) { playerVisible = false; } enemyDistance--; }

I tried a lot, but I can't seem to figure it out. Could someone help me out?