A* Pathfinding Project

Navigating through doors


#1

I’ve set up a basic grid graph for a top down 2D, but my AI gets stuck on corners when it draws a path through doors.

https://imgur.com/H9g0ufv

How can I offset the path by a few pixels so it travels more towards the center of the door?


#2

Hi

Try to adjust the ‘Diameter’ setting in the grid graph collision testing settings.
Alternatively you can adjust the Erosion setting.


#3

Unfortunately those didn’t seem to fix the problem.

Is there any way to draw the path so that it doesn’t touch the obstacles?


#4

Increasing the diameter for example should make more nodes around the obstacles unwalkable so that it doesn’t get as close. Note that even in your picture the green path doesn’t overlap the unwalkable nodes at all.


#5

I’ve increased the diameter to 2 and it just get stuck farther out now. Also he won’t be able to fit through the doorway this way

Imgur


#6

Generally the navmesh/grid graph has to be shrunk by the same radius as the character. You can think of the surface of the graph as all points where it should be valid for the center of the character to be.
Also, I’m not sure what movement script or settings you are using.


#7

I’m using the AI Path, Seeker, and Funnel Modifier scripts.

Do you have any suggestions for how I could modify the script to add a buffer zone around objects, like in this screenshot?


#8

Hi

The funnel modifier that you are using will make it find the shortest path within the nodes in the path. Removing it will make the path pass through the node centers instead like in the screenshot you posted.

Generally the buffer zone is added by doing things like increasing the diameter setting or using erosion (see my earlier post).


#9

Unfortunately removing the Funnel script and tinkering with the radius/erosion doesn’t help. Increasing them blocks the AI from going through the door anyway.

This picture from your custom movement script tutorial shows what I’m looking for

There is some room between the path and the objects. How do I accomplish that?

Thanks for your prompt responses.


#10

Could you show a screenshot of how it looks when you have increased it? Increasing the diameter is literally what I have done in that tutorial screenshot.


#11

Here is it with erosion iterations set to 2. Diameter produces a similar effect.

You can see he still gets caught on the edges and it also adds too much bulk around the walls.

Btw it’s not letting me link to imgur all of a sudden.


#12

Hi

Maybe your movement script is following the path too loosely. You can see that the path does indeed have quite a high clearance from the walls. You might need to lower the AIPath -> pick next waypoint distance field.
See https://arongranberg.com/astar/docs/aipath.html#pickNextWaypointDist


#13

That didn’t seem to work.

Could you suggest how to modify the AI Path script to draw it an extra grid square away from obstacles?


#14

By increasing the collision testing diameter by 1. You have already posted several screenshots where I have seen that this is the result.

Note that parts of the character may be outside the graph, the walkable surface are the points where the character’s center should be able to be.


#15

I discovered the issue was caused by the rigidbody, not your script.

Thanks so much for your help