Enemies colliding with others of the same type & stopping

Hello everyone, I am trying to make a game like Gauntlet, the arcade game, and I have been doing well so far, but I am stuck as I am not sure at all how I could code something. The ghosts constantly chase the player, but they get bunched up with each other, which is something I do not want to happen at all. Here is how it looks in my game so far:
gif
but I want the ghosts to “wait for their turn” like in the original Gauntlet games
BossyShyDingo-size_restricted
I am simply dumbfounded at how to achieve this, and am simply asking if anyone has any tricks up their sleeve to do this or any words of advice to get something like this to happen. So far, I’ve just jumped into Phaser with very little real programming experience (used to use Clickteam Fusion) so I apologize if this is a very idiotic or overly simple question and if anyone needs to see certain code that’s already implemented, I’ll be happy to post it. Thank you everyone, and good luck on trying to help me solve this mystery, I’ll certainly be back.

Great gifs, I understand exactly what you’re describing.

First off, don’t fret! I’ve been there too, feeling amazed at what someone else has done. Just know that you just gotta take small enough steps.

Second of all, lets take a look at the original.
If you look closely, the enemies are all following a grid. With this assumption, it looks like they can move in 8 directions - NWSE and diagonally.

What this means:

  • You don’t need colliders! Instead, you’ll want an array or something to represent the “map”, and keep track of what’s on each grid. Walls, Open Air, the Player, and Enemies.
  • Every enemy is going to have to be aware of this map so they know whether or not they can step into the next tile.

Hope this helps you get a start!

Hi again, I apologize for the very late response to this thread, I have just been quite busy, but I was able to attempt implementation of the idea Tony had, and I thank you, Tony, for the good ideas given. Of course, as a novice I am having trouble programming exactly what I would like to happen, and the current behavior is incorrect. The ghosts only move left now.

The way I “programmed” it is that each frame, each ghost is put into a tile map as a tile, and then another function is called for each ghost that populates an array with the position(in tiles) of the surrounding 8 16x16 tiles of the ghost and another array with the distance between each of those 8 tiles and the player.

Then, the minimum of all of the distances is compared to each distance, marking which tile (of the surrounding 8) is equal if the distance is the same as the closest. Still within the same function, it checks if there are walls or enemies on the marked tile, and if not, it moves to that tile. If it is populated, I wanted it to keep checking until it finds the Nth closest tile that is free, but I couldn’t figure that out. Finally, I wanted to clear the ghosts tile map for the next frame, but until writing this post I did not remember to implement this.

Through debugging, it just didn’t make sense. I logged the x values of each ghost’s closest tile to player when that is calculated, and each ghost’s “move to this x” is different, spread across the map, but with many in the negative x space. The Y values are approximately the same 2 values as the spawners’ y coordinates.

The code is here for just the enemy move, and the whole thing is here
I believe it’s easy enough to understand without comments, but I’m sure someone could find otherwise :grin:

For the 3 arrays that involve the surrounding 8 tiles, this is an image that describes which tile the index is referring to:
Untitled

I am definitely unsure of what’s wrong with the code, but I am sure it’s just badly written due to my inexperience. I am sure I will learn from the excellent advice from the great community of Phaser and javascript. Thank you all, and I will return soon and able to answer any questions sooner than I initially responded to this thread.