Thoughts on a positionin system for enemy combat

Hey people, I would like to know what you think about the logic for a system that I’m trying to build for my game

I want the enemies to follow my player when attacking, but I don’t want them crowd over the player, so I’m trying to think a way that would make the enemy stay in position around my player, in situations where the player would stay still. The goal is to have multiple enemies attacking the player but each one positioned accordingly with the pads. This whole structure around the player is a game object that follows the player.

  1. When the enemy notices the player, it will run in his direction
  2. When getting close, it will hit one of the two collider zones represented by the orange boxes on each side. Each collider zone has 5 positioning pads.
  3. When inside a collider zone, it will then see the pads, then select the first one and follow it’s position until it dies, kill the player, or the player gets too far for too long.

This kind of formation would only be noticeable if the player stand still. If the player is running, the enemy will just follow one of the the zones to get a position.

I came up with this to solve a problem which was causing the enemies to crowd over the player / the zone that prevents them to pass throught the player:
9635009--1369094--upload_2024-2-9_21-53-6.png

And to finish, these are the results I want to avoid ///// and the results I would like to achieve:

Left: enemies move like there is a bubble protecting the player
Right: enemies move like they’re keeping certain distance from the player

Please tell me y’all thoughts on that, how would you solve this problem? (no need to write the code)

Sorry for the quality of the drawings, I did them on paint xD

Your drawings are AWESOME! Your drawings makes it easy to conceive the problem visually.

Positioning pads is interesting, but feels maybe too specific.

How about just combining your current “stay at a radius” script but adding also a heuristic to try and be away from other enemies to some extent?

It would be tricky to get the prioritization on those two right… when you’re far, you want to just run at the player… but as you get close to the “standoff range” around the player you want to change to look for potential other positions that are the furthest possible from everyone else.

You could have a ring of positions around the player and a manager that hands out positions that are farthest from other enemies… and then periodically the enemies might even re-ask the manager “hey, is there any less crowded place I can stand?” just to keep it all sorta… levelling out over time…

1 Like

What I’m thinking above…9635036--1369133--20240209_anti_flocking.png

1 Like

When an enemy selects a position, you may want to have a special object that keeps track of all of the available positions and whether they have been assigned already. That way you don’t have two enemies selecting the same spot.

You could give that object a method to return the next available spot and then each enemy can call that method.

1 Like

Thanks for the tips everyone. Right now I’m building something like this:
9636596--1369646--upload_2024-2-10_18-56-31.png

  1. All the pads are inside CombatRings gameobject, which lists all of them gameobjs
  2. Each pad as a int group and bool available = true
  3. The order is defined by shortest to farthest, and available true means that no enemy is following the specific pad.
  4. When the enemy gets a certain distance from the player (can be a colliding zone) a function will be triggered
  5. The function will iterate through the available pads
  6. Then list the 10 pads nearest to the enemy (because I want at least 1 pad from each of the 5 groups to be in the list)
  7. From the 10 nearest available pads, get the only the ones from the lowest group num
  8. From the lowest group number pads, pick the closes one to be the agent destination.

And this way, the enemy will always pick the closest pad, giving priority to the best positioned ones.
My only wondering is if this will cost too much performance, it looks like a lot of lists and comparisons everytime an enemy enters attack mode

1 Like