Different AI/Units size problem

In an RTS game are units with different sizes available. One can pass through between two obstacles and the another not. Somehow the size of the Units are absolutely unsupported (just with a bad hack, place fake obtacles around obstacles at generating the graph). Some path finding assetes have a dynamic obstacles definition list to support this behavior. How do you handle this? (independently of that you don’t even have dynamic obstacles now) This is something what we cannot handle without rewriting your core code, and that would take too much time. This is something what you have to do.

This question has been asked at least 2 times :slight_smile: Hope that the following helps you.

For different sizes check:
Discussion about different sized units

For stationary obstacles use penalties and GraphUpdates. I used penalties to avoid units that weren’t moving:
Discussion about penalties

Thanks for the links. They have some good ideas, which i can use in my own solution too.

I use for the different size of units different GridGraphs. And i defined on the GridGraphs a Sphere collider for the margin, bigger units Graph got a bigger margin. This is at the time the common solution for this problem.

For the dynamic obstacles i can use now a very easy way to update the non walkable nodes with margin. I defined 2 Layers for the units, one is not an obstacle for the GridGraphs and the another is an obstacle for the GridGraphs. At starting i switch to the non obstacle layer to get a path, then until i collide or arrive at the aim, i hold this layer. After i recognize a unit in front of me, with linecasting, i stop the unit and set the obstacle layer to it (another units behind this unit avoid this unit, if they collide and repath). Then i wait a bit and check again, if the unit is still in front of me, i do a recalculation of the path (seeker.StartPath(…)). I get a way around it, because all units have an obstacle layer, they are obstacles, in the stop state.

At getting the path "seeker.StartPath(…)):

gameObject.layer = NonObstacleLayer;
AstarPath.active.UpdateGraphs (this.GetComponent().bounds);
//AstarPath.active.FlushGraphUpdates(); // i don’t need it, but for sure you can use it
seeker.StartPath (transform.position, this.target.position, OnPathComplete, MASK);
(MASK: first GridGaph=1, second = 2, third = 4 and so on)

At stopping:

gameObject.layer = ObstacleLayer;
AstarPath.active.UpdateGraphs (this.GetComponent().bounds);
//AstarPath.active.FlushGraphUpdates(); // i don’t need it, but for sure you can use it

I read somewhere, that when i start the pathfinding for each unit in a little different time window, then the framerate will be stabilized. I have to steer physical units, like tanks or cars, which are also hard to steer on the path. I have the problem, that in my state machine somehow i too often use the AstarPath.active.UpdateGraphs (…) method, which slow down the FPS from my 30 until 8 fps for a short time.

Aron, do you have a better (faster) solution, or an opinion about my way?

Now i fixed also the frame rate issue, i just lost 1-4 frames with 30 (8K triangles) units. If you want a working solution, then build at first a state machine, (with states like Idle, Move, Stop, WaitingBehindObstacle, Turn, and so on) define all possible transitions to avoid time consuming calls and to let your AI’s behave correctly in a group.