Home > Back-end >  Unity 2D - A* Pathfinding how can I make seekers avoid other seekers?
Unity 2D - A* Pathfinding how can I make seekers avoid other seekers?

Time:08-05

Working on a Unity 2D top down game with the Aron Granberg A* pathfinding asset. Does anyone know how I can have the enemies with the seeker script avoid each other? Currently they will bunch up on one another and I would like to avoid that.

In the photo below you can see the green line that shows the AI Destination Setter target. It follows the player correctly but the right cube is trying to go straight through the red cube. How could I change it so the seekers avoid one another but still follow the player?

Seeker

    public class AIDestinationSetterHyperius : VersionedMonoBehaviour {
    /// <summary>The object that the AI should move to</summary>
    public Transform target;
    IAstarAI ai;

    public void OnEnable () {
        target = GameObject.FindWithTag("Player").transform;
        ai = GetComponent<IAstarAI>();

        if (ai != null) ai.onSearchPath  = Update;
    }

    public void OnDisable () {
        if (ai != null) ai.onSearchPath -= Update;
    }

    /// <summary>Updates the AI's destination every frame</summary>
    public void Update () {
        if (target != null && ai != null) ai.destination = target.position;
    }
}

CodePudding user response:

If I'm understanding this correctly, it looks like you want local avoidance which is only available in the Pro version of the package.

  • Related