Repository navigation
P4: Add a weapon flag to use the weapon's radius in ship collisions - #8073
Open
dustinspace217 wants to merge 3 commits into
Open
dustinspace217 wants to merge 3 commits into
dustinspace217 wants to merge 3 commits into
Conversation
Ship-weapon collisions trace a thin line, so a weapon's collision radius never matters against ships. The new "use radius for ship collisions" flag makes the hull check and the shield-mesh check (normal and surface shields) sweep a sphere of the weapon's radius instead. The collision pair cull also counts that radius, so a wide shot passing a small ship is still checked. Ships with auto-spread shields keep the line, since their shield is already a sphere sweep and a wider hull check could reach past it. A flagged weapon with a zero radius also keeps the line. Weapons without the flag are unchanged.
A sphere sweep skips faces the sphere already overlaps when the sweep starts, so a flagged weapon fired from close range registered its hit on polygons deeper inside the hull than the plain line would. Flagged weapons now also check the shot's line: when the sphere hits, the face ahead on the line is used if it is nearer (keeping the sphere's hit time); when the sphere misses, a line hit within the frame still counts. This covers the hull and shield meshes. The collision cull now adds the weapon's radius only against ships, and also on the path used by turning and accelerating weapons. The comment at the auto-spread exclusion gives its second reason.
When the line's face is used in place of the sphere's hit, keep whichever hit time is earlier, so the big-ship collision path never schedules that hit later than the face it lands on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Adds a weapon flag,
"use radius for ship collisions". A flagged laser or missile hits a ship when any part of its radius touches the hull or shield, not only its center line. The radius is the weapon's object radius ($Collision Radius Override, the laser head radius, or the whole model's radius for POF weapons). Beams are unaffected. Weapons without the flag behave exactly as before.Fixes #4386
Why?
A laser with a big radius only hits a ship if its center line touches, so a shot whose glow overlaps a freighter flies through it. Goober suggested an opt-in flag on the issue.
How?
With the flag, the hull and shield-mesh checks in
ship_weapon_check_collisionuse the sphere sweep (MC_CHECK_SPHERELINE) that auto-spread shields already use, and the hit point is where the sphere touches. A sphere that already overlaps the hull at spawn skips that face, so flagged weapons also check the shot's line and keep the nearer face: a hit lands on the same face as without the flag, or one nearer the shooter.The line is kept for a zero radius and for auto-spread ships (their shield is already a sphere sweep), even with their shields switched off. The collision-pair cull also counts a flagged weapon's radius against ships, or wide shots past small ships were dropped.
Testing?
This branch vs master 94d278a, Release, OpenGL and
-vulkan. MediaVPs 5.0.3, SM1-01, and a one-table test mod:Rows of 81 shots from Lua at stationary ships:
Same on both renderers. Without the flag, every row matched master, apart from two shield-seam shots that flicker on master too. Debug logs matched master's (the Debug baseline is f0d45f6, master's parent).
Not tested: surface shields, auto-spread ships, ships with
$Collision LOD, moving targets, homing missiles, multiplayer.Anything Else?
Flagged weapons pay a sphere check plus a line check per frame, so use the flag on a few weapons. In my test, 200 flagged shots a second at a destroyer and six fighters added about 1 ms per frame (12.9 to 13.9 ms), with four times as many hits. The flag needs a line on the wiki's weapons.tbl page.
I used Claude Code to help write and test this.