beyond-all-reason / beyond-all-reason/RecoilEngine

Raise collision/predamaged events in order of distance

Open
#2,861 9 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
683
Forks
293
Avg merge
3d 2h
Merged PRs (30d)
40

Description

Hits do not occur in the exact order of nearest-object first, furthest-object last. Request would be to order them at least partially or to provide better ways of ordering hits game-side.

### Expected behavior

Collision events and effects occur in the physically-sensible order.

### Actual behavior

- Engine builds unordered sets of all collideable units, features, and shields via spatial search.
- `CheckUnitFeatureCollisions` handles first shield collisions, then unit collisions, then feature collisions.
- In each `CheckXYZCollisions`, loop projectiles in an outer loop and XYZ in an inner loop. This produces XYZPreDamaged events in no particular order.

### Motivation

BAR orders some collision events in its [penetrator code](https://github.com/beyond-all-reason/Beyond-All-Reason/blob/cf64f4477b9ed173edfc0ffc21e91260bffcaa6f/luarules/gadgets/unit_custom_weapons_overpen.lua#L276-L298). This has some perf cost so may not work well scaled up to all projectiles. Processing the sum of any single collision also has to be deferred until GameFramePost.

Since the largest effect size is vs shields, I think that is the most targetable area for improvement.

Weapons divide their damage across dense shields rather than depleting the one closest. For N shields hit per frame that a projectile hits a shield, the advantage to shield regeneration is around ((N-1)*0.5)%. Dense shields do gain an advantage over spread shields that seems to match that estimate.

Conclusion from a BAR tester:

"Four bubbles spread out can be pretty easily broken with arm flag while four bubbles stacked together as in my original screenshot take forever to break through it seems. It took ~16 min to break the four bubbles spread around more down to 40% (3x 0%, 1x 40%). Four bubbles together (four next to each other) I need to speed the game up 20x to eventually break them, it takes a really long time."

Contributor guide

Open the contributing guide

Research direction

Search the engine for CheckUnitFeatureCollisions, CheckXYZCollisions, and XYZPreDamaged event handling; start by tracing how spatial-search results become collision events. Compare the ordering approach in the linked BAR penetrator code, especially for shields. Done means collision events and effects follow physically sensible distance order without overlooking the stated performance and GameFramePost constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.