[layered grid graph] Seeker is finding path on path above it

Hey A* Pathfinding Project

We have an issue in our game where units will think they’re on the node layer above them - causing incorrect paths, and causing the unit to try and get to the first point of the path above itself.

Picture: http://imgur.com/a/k0B2x

Version: 3.8.1 (2016-02-17)

Upgrading to the latest version and hoping for a fix isn’t viable right now - but regardless first off I’d like to know if there are any basic things to sidestep if this issue is happening. Any ideas?

Any help would be hugely appreciated

Hi

Where is the pivot point of that character (or rather, the point from which the paths are searched). I would recommend that you put it near the character’s feet to avoid these issues.

Hey Aron thanks heaps for the fast reply!

Here’s the pivot/center point of the character, which is the object that has the Seeker component

Image: http://imgur.com/a/LHT8t

It’s at the base of the character

Included are the Seeker settings and the node graph settings it’s using. I’m paused in the scene here and can provide other details if you’re online now

Hi - apparently this thread is being hidden automatically - might not have liked my Imgur links?

Hi

Yeah, the forum software found that to be suspicious, but I think I have fixed it now.

Try this script: http://pastebin.com/sLL0tVdL. That will draw a line to the closest node and that might help us debug the issue.

Hi Aron,

In my implementation I’d been using custom node blockers to remove nodes within a bounds around an enemy - resulting in enemies having no very close nodes within reach. I’ve discovered that GetNearest seems to jump to a higher layer if there aren’t any nodes very close by. So I’ve scratched that implementation.

I’m now trying to use the tag system to add a tag volume around enemies, and allow the current enemy to traverse that tag, while disallowing other enemies. This seems like a better idea.

However currently I’m struggling to get the nodes to update and take into account the tag volumes that are being created. I’m doing it the same way I was previously cutting nodes, like so;

void NODEBLOCK_Recast_Check_Nodes()
{
    GraphUpdateObject guo = new GraphUpdateObject(my_box_collider.bounds);
    guo.updatePhysics = true;
    AstarPath.active.UpdateGraphs(guo);
}

Now, with a GraphUpdateScene component here I’m not seeing any changes to the grid take place after running the above code on the object:

If I do a full scan via the Astar Path it will work and the tag volume gets added:

Is there a proper way to be adding and removing tag volume from code?

Thanks very much

I see I should be using “Apply()” on my GraphUpdateScene

I’m now looking for a way to remove the tag penalty from those nodes after the enemy is done with them.

Hey Aron,

My question is:

When I have used GraphUpdateScene to create a tag penalty on some node - how do I then clear that tag penalty from those nodes, using the same bounds?

Setting the tag to basic ground, reapplying, and then moving it - seems to do the trick. Thanks. Will report back on if this helps with my Layer issue.


Hey Aron :joy:

Sorry for bothering you with all that mess - I’ve pinpointed the issue here.

I’ve put in your debug code

The issue is, Seekers will prioritize the layer above themselves for the nearest node if they don’t have any immediately close nodes next to them (they even ignore nodes 1-2 Unity units right next to them)

As you can see in the picture, ideally the Seeker should be weighted to grab the nodes that are 1-2 Unity units away on the same layer as themselves.

Is there some sort of value to change that allows Seekers to increase the size of the nearest node check? Or perhaps some more nuanced get nearest node code?

Another example

This Seeker has node right next to him he could choose, but instead decides the floor above is the nearest node.

Hi

Hm… Ok so it might be that the layered grid graph is giving up after it has found a valid node. As a performance optimization it only searches outwards for 2 more nodes (radius) after it has found a good node.
You can increase this value in the GridGraph class, but a better solution in your case might be to use a custom NNConstraint to make sure this doesn’t happen.

public class MyNNConstraint : PathNNConstraint {
    public float yCoord;
    public float someThreshold = 2;
    public override bool Suitable (GraphNode node) {
        return base.Suitable(node) && Mathf.Abs(((Vector3)node.position).y - yCoord) < someThreshold;
    }
}

Where you would set this like

 var path = ABPath.Construct(...);
 path.nnConstraint = new MyNNConstraint {
      yCoord = transform.position.y;
      constrainArea = true;
 };

This will make sure it will not pick any nodes that are further away on the y axis than “someThreshold” world units.

1 Like