HomeWildfire Games

Add a simple 'pushing' logic to unit motion to improve movement.
Concern RaisedrP25182

Description

Add a simple 'pushing' logic to unit motion to improve movement.

This implements a form of crowd movement that I've generally called 'unit pushing' in the last few years.
Essentially, any two units will push each other away when they're too close. This makes it possible to ignore unit-unit obstructions, and thus makes movement much smoother in crowds.
This first iteration of this system only allows pushing between idle units and between moving units (i.e. a moving unit does not affect an idle one).
This is because the unitMotion logic to detect it is stuck & needs to use the pathfinders starts breaking: units can fail to move because they are pushed away from their intended movement, and the current logic fails to handle this gracefully.
Thankfully, the most value of this patch in terms of player experience is found in the improvements to group movements and shuttling.

Other impacts:

  • As the short pathfinder is called less often, we can increase the starting search range & reduce the # of max turns, both improving collision recovery.
  • The performance of idle units is slightly worsened, as they must be checked for idle-idle collisions. If needed a 'sleeping' system, as used in physics engine, could be implemented.
  • In general, however, expect slight performance improvements, as fewer short paths are computed.
  • Gathering efficiency should increase slightly, since shuttling times are likely reduced slightly.
  • As a sanity change to improve some edge cases (units that say they're moving, i.e. pushable, but don't actually move), the 'going straight' logic is turned off if a short path has been computed. This requires a few cascading changes to work correctly.

Technical notes:

  • To reduce the cost of the n^2 comparisons that pushing requires, units are only compared within a small square on a grid which is lazily reconstructed each turn. The overhead seems rather small, and this is much simpler than keeping an up-to-date grid.
  • The design is intended to be parallelisable if needed someday.
  • The pathfinder's CheckMovement ignores moving units in UnitMotion, as that is now the spec. Idle units are not ignored, which is required for the 'collision' detection to work correctly (see above).

Refs #3442 (not fixed - idle units are not pushed by moving units).
Fixes #5084 (the overlap can still happen, but units will push each other away).

Differential Revision: https://code.wildfiregames.com/D1490

Event Timeline

Imarok added a subscriber: Imarok.Apr 3 2021, 4:06 PM
Imarok added inline comments.
/ps/trunk/source/simulation2/components/CCmpUnitMotion_System.cpp
47

extertexert
Seems like you missed my inline on D1490 ;)

Stan added a subscriber: Stan.Apr 6 2021, 2:53 PM

Might have been placebo effect, especially since I haven't played since A24, but it seemed to me like this made the game laggier when moving groups of units? Could be something else, just thought it was worth mentionning.

Langbart raised a concern with this commit.Apr 1 2022, 8:50 PM
Langbart added a subscriber: Langbart.

#6486
Related to rP26680

This commit now has outstanding concerns.Apr 1 2022, 8:50 PM