# Question Thoughts on a positionin system for enemy combat

Discussion in 'Scripting' started by wingsneon, Feb 10, 2024.

1. ### wingsneon

Joined:
Jul 5, 2018
Posts:
23
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:

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

Last edited: Feb 10, 2024
2. ### Kurt-Dekker

Joined:
Mar 16, 2013
Posts:
38,705
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...

wingsneon likes this.
3. ### Kurt-Dekker

Joined:
Mar 16, 2013
Posts:
38,705
What I'm thinking above...

wingsneon likes this.
4. ### kdgalla

Joined:
Mar 15, 2013
Posts:
4,637
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.

wingsneon likes this.
5. ### wingsneon

Joined:
Jul 5, 2018
Posts:
23
Thanks for the tips everyone. Right now I'm building something like this:

1. All the pads are inside CombatRings gameobject, which lists all of them gameobjs
``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

Kurt-Dekker likes this.