Currently, I'm simulating physics impact forces for local avoidance of units but this method sometimes pushes units out of formation and has very undesirable effects when units clump up.
For RTS games like Starcraft 2, how is local avoidance done? Are physics simulated or an omnicient controller decides where everything should be? I know this question might be a little broad so I'm asking specifically for how to achieve the local avoidance behaviors of Starcraft 2; though anything that works will be very appreciated.
I'm not looking for any code - just useful resources or explanations of how Starcraft 2 (or similar games) handles local avoidance.
Currently, I have collision detection (with penetration vector), collision forces, and movement by velocity implemented. Every unit is checked against another for a collision - if they collide, the objects are immediately offset by the penetration vector then the collision force is applied. Then another loop moves the objects by their velocities and applies drag to the velocities. The offset mitigates the problem of excessive collision forces applied on clumped units, but units still sometimes shoot out.
The solution I'm looking for needs to satisfy the following requirements (as in Starcraft 2):
- Objects musn't overlap; or at least overlaps must be eventually resolved.
- Objects don't push each other away more than necessary so 2 units can stand and move next to each other in a formation.
- There should not be any weird behaviors when objects clump towards the same destination.
- Can support units of different sizes, and even different convex shapes.
What I've been thinking of so far is instead of detecting for collisions, detect for future collisions so the overlap never happens. Then apply the constraint, making sure the 2 units' velocities don't cause them to overlap. I'm still tinkering with the algorithm for restricting movement beyond the overlap.