How to make enemies detect each other?

dreph

• Posts: 142
Ok, so let me start off with my understanding of things.

I have a player follow behavior, it checks player 1 (and 2 if two players are on screen) and adds their X and Y locations to a list.  I used a loop to handle it all, and everything is working splendidly.  X and Y locations for Player 1 and Player 2 are being tracked in a list and all is well.

Now, what I want to do is actually have the enemies stay away from each other... but I have two ideas for an approach to this logic and I would love some input.

My first approach is to create a new list for enemy locations.  The problem is that I plan to have approximately 12-16 enemies on screen at once at some point, and I want to know, before I jump too far into it, if anyone has experience messing around with Always updating a list and issues with performance?

My second approach is to make each enemy a "sensor" and compare their own X/Y locations to the last collided enemy actor, and adjust accordingly.  Currently the enemies move directly towards the closest player, but I'm sure that I could easily add a quick "if not colliding with enemy group" to their follow behaviors, and have them avoid their buddies by "if collided with enemy group, compare X/Y and move away"

What are your thoughts? I would love to get some feedback before I delve in.  Thanks!

RosalinaGalaxer

• Posts: 239
Always updating a list and issues with performance?
I'm currently frantically working to get a bullet hell game done in time for Smash Ultimate, and it updates multiple lists every frame with no drop in performance on Flash. I am running it on simple physics, though, so that may be a factor that's helping.

Otherwise, there is a block in the Easy Math Extension that gets the distance between two points. You might be able to use that in some way.
Ģ̷̓l̴̥̒͑̕͝ì̷̘͈̬͈̖̂͂̔̕t̷͔͇̯̥̬̀̽̓͜͝c̵͇̦̼̮̉̐̈́̕͝ͅͅḣ̵̡̫̞͚̐̅ͅë̶̗̦̪̖͚̜́͊̄͑s̵̺̹̖̼̥̃.̴̮̫͐ ̶̛̓̇̾̎

“I have never seen a more heated discussion about context, jazz, and cats.” - VanillaButterz

dreph

• Posts: 142
Thanks for that! It's good to know I can get away with it.  I might be able to use simple physics as well because I'm not using gravity for this project.

Also, I was referred to the Easy Math extension a week or so ago, but it's easy math.  I figured that stuff out already.