2D How to create a Separation Movement Script

Godot 4.2.1

Hey everyone!

I’m hard stuck on navigation for AutoBattler 2d TopDown game.
What I don’t understand essentially is steering - I have been able to implement it so the velocity is dynamic but never to the effect it would work and the units will walk around each other toward the target.

I have a visualized example.

There are 3 teammates running toward the same target. Two of them have already reached it and in attacking state.

The third one keeps getting stuck because the rays are basically trigering in order and making him jitter in place.

Maybe someone has had experience with rts games or something that really needs avoidance or separation systems.

Thank you for reading and possible offer of advice friend!

By the way -
I have tried NavAgents, but the avoidance there simply can’t deal with these types of situations.

Your navigation system needs to recognize when an agent is not able to reach it’s target and search for a new path.
If you go straight towards a target, the way can be blocked.

Another option would be to introduce waiting. So if you can’t reach a target. Simply wait for it to be free. But that may not work for you.

The problem is that all of these units are navigation agents and they don’t exactly think of each other as obstacles in navigation.

So if I check if navagent.target_is_reachable - it comes out as true, even if the agent is clearly stuck.

I was trying to research ways to rebake the navmesh dynamically but I don’t think there is a way.

I’m don’t really understand how it’s done in games like Warcraft 3 where the units instict is to surround their target if there are a lot of them.

I am 99% that contextual steering is the solution, I just wish someone who implemented it succesfully in the past will share on it

Games like Warcraft3 use a grid for pathfinding so each unit can occupy cells.

It does not get more intelligent than that. The reason why it is so easy to block units in Warcraft3 by dancing another unit in front of them. Everytime the unit timer queries a new path the cell is blocked by the dancing unit so the path selects a long detour.

Most RTS games use grids for this very reason, to occupy space. This is not really the purpose of a navigation mesh that wants to cover as much surface as efficiently as possible with large polygons.

In Godot you would use AStar2D/AStarGrid2D and with an override function for the cost. Then have a separate cell mapping, e.g. a Dictionary, for your units. When the path override function wants to use a cell that has another unit using it you reject that cell or increase the cost so paths will go around that unit Warcraft3 style.

2 Likes

THX I will give it a try!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.