Support Forum

Prevent any objects from occupying the same grid node

I’ve been trying to use a recast graph and RVO for my game and after weeks of trying just could not make it function the way I need it to (though I’m sure it can do what I need, I just can’t figure it out). So I decided to try out a hexagon grid graph. So far so good but there’s one major issue: two objects should not be allowed to occupy the same grid node.

I’ll regularly have ~200 agents that are pathing around this graph and need to respect each other’s space (something that RVO did for recast graphs but doesn’t do for grid graphs from what I can tell). I’ve tried doing this by writing a dynamic node blocker script based on DynamicGridObstacle but the biggest issue is that each object needs to keep a list of blockers to avoid. I’ve got to keep refreshing this list as the agents in the scene are defeated/revived/added and remove the agent itself from the list so it doesn’t block it’s own path.

Surely there is a better way to go about this as what I’m using now only kind of works.

Additionally, I want to be able to snap my objects to the grid both in editor mode and as they’re spawned. I wrote a little editor script that does this, but it will put two agents into the same node and I just can’t figure out how to stop this from happening either without some complicated and lengthy if/else statements that Raycast the node to see if something is in it, log the node, mark it as unwalkable, and scan again and again. Again, this kind of works but is buggy and certainly there’s got to be a better way.

Any guidance would be greatly appreciated.