Force AI agents to stay out of a min-range around player (Gif included - pro version)

Hi there I am making a Virtual reality melee game, in which there can be multiple enemies facing you at any given time. It is imperative in virtual reality that I have the space to move and fight so I cannot accept agents being inside the melee range of the player as this messes with clipping, and all sorts of other things.

I am wondering if there is a way to make sure that multiple RVO agents will completely avoid pushing each other ontop of the player in an attempt to get closer.

I have set RVO controllers on all agents and a simulator in scene. The player has an rvo controller as well and high priority on avoidance. but still they push each other in order to get closer to the player which causes the problems.

Any help would be greatly appreciated.

Gif showing issue

Hi

It’s quite hard for the agents to know in this case if pushing is necessary or not. However a reasonable heuristic might be something like this (pseudocode)

bool somewhatCloseToPlayer = Vector3.Distance(player, transform.position) < 5;
bool veryCloseToPlayer = Vector3.Distance(player, transform.position) < 2;
float raycastDistance = 1;
if (veryCloseToPlayer || (somewhatCloseToPlayer && Physics.Raycast(transform.position, (player - transform.position).normalized, raycastDistance))) {
    ai.isStopped = true;
} else {
   ai.isStopped = false;
}

What this code does is essentially:

  • If the agent is really close to the player, stop trying to move closer
  • If the agent is somewhat close to the player and there is something in front of it (in the direction of the player), stop trying to move closer
  • Otherwise continue moving

There is also some code I have written for an RTS demo that prevents agents from trying to move closer once they reach a certain density, however I’m not sure if that will work much better than the above heuristic here, might work worse. (see https://www.youtube.com/watch?v=wBUdMXeeej0).