Log In  


Cart #topdownai-0 | 2022-08-14 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
15

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.

If this was helpful or interesting for you, please give my itch.io page a visit: https://profpatonildo.itch.io/ or consider buying me a coffee: https://ko-fi.com/profpatonildo70266

15


By the way, it would be fun to see how you fellas optimize and better this system, as it works, but is kinda janky if you look at it for too long.


1

I really like this sensor approach, pretty nifty little idea.


1

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 !


@northstategames thanks! Yeah, I know there are algorithms to do path finding, but I think for fast paced or action games they can be too performance intensive or too complicated to implement. This sensor approach performed better in my testing.


@dw817 Thank you! I'm sure you'll enjoy my next project :D it will take me a while to complete it, but it will be an arcade game using this system, with cute characters.


1

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:

https://www.lexaloffle.com/bbs/?tid=48231

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.


1

Here now, @profpatonildo. You might be interested in 005 which is an old arcade game. See how they shine their flashlights to find the enemy.

I did something like this years ago but not with the effectiveness they did.

https://youtu.be/Z34HiNofsLg?t=18



[Please log in to post a comment]