Most Basic "Pathfinding" / Player Follow / Enemy Chase AI


WSAD / Arrow Keys / Right Click to move

This is one of the most basic ways to make Enemies follow your Player object (only after seeing the Player).
I realized how complicated many of my pathfinding examples are, and I wanted to make a simplified one where (hopefully) more people can actually understand how the code works.
If you look in the code, could you please let me know if you understand it or not?
The basic idea is that the Player keeps adding their X and Y coordinates to the front of 2 lists, which get shared with the Enemies. The Enemies check if they can see the 1st position on the list, and if not, then they check the 2nd, and if they can’t see that one, then they check the 3rd position, etc. until they find a past Player position that they can see, and then they aim for it. This essentially the “Player Trail” concept but without an extra “Trail” object.
Again, please have a look in the code, and let me know if you understand it (or if there’s something I can do to make it more readable). Feel free to ask questions, too.
And finally, like most pathfinding examples I’ve made, this one can cause performance issues if the player’s trail is too long XD

Questions or Comments?