How to make NPC avoid other NPCs while chasing player?


Basically Im setting the target of each npc to be the player position and they should do something like circle around the player and attack. I have tried RVO Controller but they still keep standing very close even going through one another. Is there any other solution for that?


Deciding where the agents should walk to is up to you. Depends on the type of game you’re trying to make.

First and foremost the behaviour should decide where the agent wants to stand, flee, attack etc…

With multiple agents you could add some more complex systems.
Many people tend to make a Agent Manager that wil assign attack positions etc to the agents.

RVO is there to fill in the gaps. And have a better result.
A system should never be based on RVO, RVO is like that little bit of whipcream you put ontop to make it just better.

For example in our project, we all ow 2 - 4 agents to stand in a close circle around the player (depending on the difficulty setting). Other agents are just standing around a bit. Until a spot becomes available around the player.

1 Like

Okay so basically the agents should decide how to surround the player. Are there any examples how this can be achieved ?

You can easily calculate points in a circle around another point using basic Trigonometry
for example:

public void CalculatePointsAroundObject (AIBase[] agents, Transform targetTransform, float positionRadius) {
    float subAngle = 360f / agents.Length;
    float currentAngle = 0;

    Vector3 currentPos = targetTransform.position;

    for (int i = 0; i < agents.Length; i++) {
        agents[i].destination = new Vector3 (
            Mathf.Sin (Mathf.Deg2Rad * currentAngle) * positionRadius + currentPos.x,
            Mathf.Cos (Mathf.Deg2Rad * currentAngle) * positionRadius + currentPos.z);

        currentAngle += subAngle;