I am making an AI for an 8 directional game. So far, I have made it so that enemies see the player if there is not an obstacle in the way, using a line that I draw between each enemy and the player. Now, I have also made it so that each enemy runs to the last point where they saw the player. The problem is, they sometimes run into obstacles doing this. I want them to see that the obstacle is coming up ahead, and change directions instead of running into the wall. Is this possible, without using any excess objects? It would be easy just positioning a "view line" object that pointed in the direction that the enemy was looking, and then checking for overlapping of obstacles from there, but I don't want to use too many active objects for the AI, due to memory consuming. Is this check for obstacles ahead possible to do with math instead? Preferably with a chance to alter the distance of detection between the enemy and obstacle?
Hope I am making myself clear :P