Opened 6 years ago

Closed 3 years ago

#5084 closed defect (fixed)

Overlapping units

Reported by: temple Owned by: wraitii
Priority: Should Have Milestone: Alpha 25
Component: Core engine Keywords: pathfinding
Cc: Patch: Phab:D1490

Description (last modified by elexis)

Usually units collide with each other, with the exception being units in the same formation. If you stop and disband the formation while units are in the middle of rearranging, some of them may be overlapping. When you now move them, they'll test for collisions against each other but TestRayAASquare doesn't count inside-to-inside collisions, so they're free to move through and on top of each other.

This situation can also happen when units build something and aren't close enough for the foundation to trigger a leave foundation command, but are close enough so that moving onto to the building is inside to inside and isn't counted as a collision.

https://trac.wildfiregames.com/raw-attachment/ticket/5084/screenshot3577.png

https://trac.wildfiregames.com/raw-attachment/ticket/5084/screenshot3561.png

Attachments (2)

screenshot3577.png (1.8 MB ) - added by temple 6 years ago.
screenshot3561.png (1.6 MB ) - added by temple 6 years ago.

Change History (5)

by temple, 6 years ago

Attachment: screenshot3577.png added

by temple, 6 years ago

Attachment: screenshot3561.png added

comment:1 by elexis, 6 years ago

Description: modified (diff)
Keywords: pathfinding added

comment:2 by wraitii, 3 years ago

Milestone: BacklogAlpha 25
Patch: Phab:D1490
Priority: Must HaveShould Have

Unit pushing deals with this.

comment:3 by wraitii, 3 years ago

Owner: set to wraitii
Resolution: fixed
Status: newclosed

In 25182:

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 n2 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

Note: See TracTickets for help on using tickets.