This is an example of how to do enemies that somewhat follow and try to seek the player.
It works like this:
- each enemy shoots sensors towards the player.
- if a sensor hits a wall, it gets deleted.
- if a sensor exceeds a set amount of time, it gets deleted.
- if a sensor hits the player, a position gets marked as a target for the enemy that emitted that sensor.
- enemies will move to their target positions.
- enemies will roam randomly when the player hasn't been detected.
- enemies have a fov: sensors are emitted only if they are inside the range of this fov.
- if the player gets too close to enemies, they will detect the player, regardless of their fov.
- if the enemy can't find the player, it will get deactivated after a set amount of frames or after it reaches its target position.
This example also features:
- a bunch of helper functions;
- animation system;
- y sorting system;
- outlined sprites;
- outlined text printing;
- floating text messages system.
I simply LOVE the mechanics of this game, @profpatonildo. It's Metal Gear Solid or even 2D Castle Wolfenstein with cute little monsters instead of serious soldiers !
Very nice ! I would definitely like to see this game progress.
Starred and ❤️ Favorited !
You're very welcome, @profpatonildo. One thing though. It seems a might unfair to the player that once the baddie catches sight of the player, if the player ducks around a wall the baddie STILL has his sight in the DIRECTION of the player and moves with the player - which should be impossible with normal sight.
Here, I wrote a cart sometime back to demonstrate this:
Now while mine pretty well cheats as the bad-guys are looking in all directions at the same time - and it only uses a beeline to see if they can "see" the player, they still do not see the player beyond the wall.
@dw817 Very interesting! I'll go through your code to check it out better. I was debating that with myself as well. What actually happens in my cart is the enemies mark the last known position of the player and try to move there to investigate. I was considering making it so they would lose track of the player as soon as they lost sight of it, but I thought the enemies would look smarter if they still continued to move until they reached their target position (or the seek timer counted to 0, in case the enemy got stuck). I decided to do that as well, because it is fairly trivial to remove that behavior if it makes the enemies overpowered.
[Please log in to post a comment]