I guess I'm trying to block a occupied node, how do I do that?

Hey guys, I’m very new at this so please go easy on me. I just started playing around with A* pathfinding in Unity and I find it very interesting, but I’m stuck on something.

Let me first explain what my goal is so that you understand what I’m trying to do. Right now I’m simply trying to make a tile based game with grid movement for both the player and ai controlled characters.

Both the player and ai characters use A* pathfinding to move around. How do I make a tile inaccessable by anyone if there’s already a character occupying it so that the pathfinding won’t use that tile for anyone to find a path?

I’ve tried placing all characters under a layer which I then checked for collision detection and then rescan the graph in realtime, but that seems to interfer with the pathfinding for the character occupying the tile.

Sorry for my extreme noobyness, I hope I didn’t make anyone cringe too much… Thanks in advance :wink:

edit:
I just realised I pretty much exactly have the same problem as this guy in this thread:
http://arongranberg.com/vanillaforums/discussion/2759/moving-obstacles/p1

but the last part isn’t solved. Using penalties, characters can still move through eachother if they absolutely have to. Any ideas?

edit2:
I pretty much figured out a way to do it. I’m setting a penalty on nodes characters currently stand on, and I also loop through each node in a path and make sure none of them have said penalty. It’s working exactly the way I want and expected it to but please feel free to tell me if there’s a better and more efficient way to do it, I’m still all ears.

1 Like

Can you post some code how you do this? I’m currently working on a project, and I need exactly what you’ve described in this thread. Thanks!

I make the occupied nodes unwalkable if the unit is not moving, and reset it to walkable again as soon as he’s moving.

        bounds = GetComponent<Collider>().bounds;
        bounds.extents = new Vector3(0.5f, 0.5f, 0.4f);
        guo = new GraphUpdateObject(bounds);
        guo.modifyWalkability = true;
        guo.setWalkability = false;
        AstarPath.active.UpdateGraphs(guo);
2 Likes