Navigate through center of a corrider

Hi, I’m trying to navigate through a building via A*, It works well but the only problem is it chooses the corners to navigate despite what I’m looking for is a way to navigate via center of the corridors. I can do something like that via “Thick Raycast” or “Collision Testing” and increase the “Diameter” or “Height/Length” but the problem is either of these ways will block the doors and entrances and are not a good option on navigating in building floors.
I’ll appreciate if you can help me with this.
Thanks

Hi

What you could do is to activate tags based on the distance to the walls (see https://arongranberg.com/astar/docs/gridgraph.html#erosionUseTags). Then you can set different penalties on the seeker for different tags. So the tag closest to the wall could have a penalty of 10000 and the next one a penalty of 5000 and so on for example. This will make it strongly prefer to walk in the center of the corridors, but it will still allow it to pass through narrow entrances (even though it will prefer to use wider entrances if there are any).

Thanks very much Aron
I tried your tips and I can see different colors around my walls when my debug is on tags but when I switch my debug mode to penalty it shows everything in green mode and penalties doesn’t seem to be applied to the floor.
I have set my “Erosion iterations” to 5, and “First Tag” to 1 , and also position penalty to “Offset” 1 and “Factor” to 10 and also have set 50000, 10000,5000, 1000 to tags of 1 to 4.
I’ll appreciate if you can also help me with this.
Thanks
16%20PM

Hi

The penalty that you set for tags (on the Seeker component) will not show up using the ‘Penalty’ visualization because they are agent specific.
What is the node size of your graph?

You can also use the debug mode G score or perhaps F score to see how the search progresses. Also enable ‘show search tree’ to make the visualization easier to understand. The G score is the cost from the start node to the given node and F score is the estimated total cost of the path when the search reached a given node.

Are you sure you have set the tag penalties on the Seeker that is doing the path calculation in this case? Also, are you sure that you are using the Seeker’s path calculation methods and not calling methods on the AstarPath class directly, as that will bypass the Seeker. If you are using a built in movement script like AIPath then those always use the Seeker.

Thanks very much Aron,
I have attached the AIPath and Seeker scripts to my A* gameobject. my node size 200*200 on PathTypesTest scene.
I think I have been using the AStar pathfinding methods and it was overriding the Seeker script. As I see in the script it is “AStarPath.StartPath§”
I’ll also appreciate if you can help me on how to do it with AIPath and Seeker scripts.
Thanks very much

Hi

If you just want to move the character, then setting the ai.destination property to wherever you want it to move will be enough (alternatively you could use the AIDestinationSetter component to make it move to a Transform, if you set the destionation property make sure you do not also use the AIDestinationSetter component though).

Hey, pretty much the same question so I’ll just add it here. Basically the problem I’m having is that my (flying) unit gets snagged on corners, so I guess what I want is to make it round the corners with an appropriate amount of distance, and using tags to make sure it prefers to stay further away from the wall seems like a good way to do this. Probably doesn’t matter, but this is 2D “SideScrolling” view.

I think I can get the distance for corner rounding to work with some tweaking. The problem I’m having is that because of how tag erosions work, when it reaches a fork in the road, the fork will have tags which are further away from the wall than just going straight, so in an area like this: https://www.dropbox.com/s/wjncxkftys5e2sx/Screenshot%202019-02-18%2010.30.54.png?raw=1

When the path is to go straight, it will instead dip down to the teal/red areas (and then get stuck on the corner there.) I imagine there might be a way to get around this by tweaking the weights of the penalty but not sure how.

Also not sure if this is intentional for some reason I don’t understand, but when using Erosion uses Tags, it only seems to work (at least it is only able to draw the colours of the Tags), if I select the First Tag to actually be the second Tag (e.g not Basic Ground.)

Thanks very much Aron, I tried ai.destination and in the editor the agent moves according to the penalty tags, What I wanted to also ask is how I can now get this path to draw a line like in the examples.
Thanks again very much for your great help and support.

If you mean drawing the green line showing where it’s going, the ‘Draw Gizmos’ tickbox on the seeker does that to make it show in the Scene view while it’s running.

For smoothing the path once it’s picking the right tiles, a modifier can help: https://arongranberg.com/astar/docs/modifiers2.html

1 Like

@Earl

It’s a bit tricky to fix that scenario.

Possibly what you could do is to do a second manual post processing path of the graph and apply this rule to all nodes:

  • If the node has 5 or more neighbours with a lower tag than the node’s own tag (i.e. those nodes are closer to the wall) then replace the node’s tag with the lower tag.

If you apply that post processing rule for a few iterations (say 3) then I think it will filter away most of these cases for you.

Make sure that you store the new tags separately first though, because otherwise the graph will change while you are iterating over it and might cause the rule to be overly aggressive.

See also https://arongranberg.com/astar/docs/graph-updates.php#direct