2D Grid Map doesn't respect NPC collider size

I’m sure this was asked before, but I’m trying to make a 2D RPG and am using the pathfinder, and even though it finds all the unwalkable grid nodes correctly, when I move between a large object, it won’t move properly: It’ll try to move from the center but the shape of the walker doesn’t allow it.

Example:

My NPCs have a specific area that is their collider and I want the NPCs to walk around that area, or they get stuck moving upward in a way that won’t work.

How can I fix this?

Thank you for your help.

Hi

You have to adjust A* Inspector -> Grid Graph -> Collision Testing -> Diameter to properly account for the agent’s size.

I will have multiple agent sizes though. And the game is moddable, so I can’t account for all agent sizes.

It still happens sometimes, even after increasing the diameter considerably.

I tried using your grid shape traversal script but since my player character already has a collider, the area around it is being removed and so it doesn’t work since those areas are unwalkable. Is there a way to disable that during the pathfinding of a specific character?

Hi

Here is a tutorial about that: https://arongranberg.com/astar/docs/multipleagenttypes.html

Generally you do not make the agent’s collider collide with the world. You normally assume that the pathfinding is working ok and if there are any small discrepancies then the agent will not bumb into things (instead it may clip a corner slightly, which is less noticeable).

You player character’s collider should also not be included in the scan. Make sure your agent is on a separate layer and not included in the A* Inspector -> Grid Graph -> Collision Testing -> Layer Mask.

Oh okay, so basically colliders shouldn’t be a thing if you’re moving through pathfinding. In that case, how can I deal with NPCs moving around and going through other NPCs?

Also, should NPCs be included in the scan?

Thank you very much for your time.

NPCs should not be included. Only the static environment should be included.

NPCs going through other NPCs is usually handled by some kind of local avoidance. See for example: https://arongranberg.com/astar/docs/local-avoidance.php

Thank you very much, I think everything is clear now :slight_smile: