I’m making a 3rd Person RPG. When multiple enemies get close to the character to attack, they’re bumping into each other. I can’t figure out how to keep them from grouping together like that. Especially when I move away and they’re running from the same direction. How can I set a minimum distance they can be from one another?
Also, my EnemyAI is built in the Behavior Tree (Patrol, Chase, Investigate, Attack). Right now, they run up and attack and keep attacking. I would like to make them better so they would run up, attack and then back up/move away some as defense. It would also help the swarming issue.
If you only want them a certain distance from each other, but don’t want anything else affected (i.e. you don’t want their distance from walls or the Character to change) you can add a Sphere Component to the Enemy class, then set it to ignore everything but the Object Type to which the sphere component belongs (you can even create a new Object Type called EnemyDistanceSphere or something). That way, they hit each other’s spheres and don’t get closer to each other than that.
I haven’t tried this with player characters, but what I do when there are many enemy characters attacking a large object like a building, is to calculate locations along the perimeter of the building. Like for example, if it’s a spherical power core that the enemy is trying to destroy, you can calculate points on an imaginary circle along the perimeter. You can then just get a random location from these points and set it as the target location for each enemy unit. You can even go a step further and keep track of locations that have already been assigned, and only assign unoccupied locations to new enemy units. It works quite well for stationary objects, but for a moving object like player character, you’d have to update the enemy target locations dynamically.
I don’t know if this would work, but have you tried setting the can affect navigation tickmark to true? I believe that always updates the nav mesh bounds to go around the pawn instead of completely ignoring the fact that it is there every time it moves.
I made a collision sphere with a new object response called EnemySpace that only blocked other EnemySpace collisions. Then put one on each enemy and they stayed as far apart as I made the collision sphere.
In UE5, there is this option called Acceptable Radius, and it ends the MoveTo Task when the AI pawn is just 200 unit away from target actor or location.