Support Forum

3x3 Units, GridShapeTraversalProvider & Path.calculatePartial

Hello, recently purchased your asset and it has greatly helped to simplify AI pathfinding for my current project, thanks.

I was curious if it was possible for my units using the GridShapeTraversalProvider to pathfind to the nearest possible node if the current target node is at an invalid position. For example, I am testing a unit with a square shape of 3 (3x3) using the default provided GridShapeTraversalProvider. The pathfinding works great for avoiding getting too close to walls as well as tight spaces, however when the player (The pathfinding target) moves along/bordering a wall tile, the AI is unable to construct a valid path. I have tried using path.calculatePartial in order to get the large unit to move to the nearest position however that did not work.

I have provided a video to better explain the situation.
https://drive.google.com/file/d/1-XS1rx8-atRNZRYtX15Qnnmv8Pa8sPNw/view?usp=sharing

Here is the current code I am using to calculate a targets path.

// Start pathfinding to target (This is on my custom character controller component)
    public void StartPath(Vector3 position)
    {
        ABPath path = ABPath.Construct(transform.position, position, null);
        path.calculatePartial = true;
        path.traversalProvider = GridShapeTraversalProvider.SquareShape(_unitSize);
        _seeker.StartPath(path, OnPathComplete);
    }

I am receiving this error when the player is at an invalid position:
“The node closest to the end point could not be traversed”
As well as (Although much less frequent):
“The node closest to the start point could not be traveresed”

Note* I am using my own character controller implementation and not one of the built in AIPath components.
Note* I have tried increasing the max nearest node distance.

1 Like

Hi

Hmm. I think in this case it would help if the NNConstraint on the path also knew about the traversalProvider. By default it is ignored, but I really should change that.

You can subclass the PathNNConstraint to do this:

class MyNNConstraint : PathNNConstraint {
     public ITraversalProvider provider;
     public Path path;
     public virtual bool Suitable (GraphNode node) {
          return base.Suitable(node) && provider.CanTraverse(path, node);
     }
}

and then do

path.nnConstraint = new MyNNConstraint {
    path = path,
    provider = path.traversalProvider,
};

I think that should work.

1 Like

Worked beautifully. Thank you so much :grin: