Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unpredictable jump damage from excessive velocity on unit collision #5468

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cktang88
Copy link
Contributor

@cktang88 cktang88 commented Mar 5, 2025

Took a stab at fixing https://zero-k.info/Forum/Thread/38027, this approach just bounds max collision damage to the specified landing weapon. If there's no specified landing weapon, bounds the max val to 20% of health (arbitrary, happy to change this to whatever val is best).

If that's not ideal, I can also do it by clamping velocity as Googlefrog suggested in that thread.

NOTE: most of diff is from file formatting in line w the Lua style guide (first commit).

The commit to actually do the change is all in this commit

Highly recommend split view in GH review UI for viewing formatting changes.


local damgeSpeed = math.sqrt((nx + tx*TANGENT_DAMAGE)^2 + (ny + ty*TANGENT_DAMAGE)^2 + (nz + tz*TANGENT_DAMAGE)^2)

local damgeSpeed = math.sqrt((nx + tx * TANGENT_DAMAGE) ^ 2 + (ny + ty * TANGENT_DAMAGE) ^ 2 +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This newline (and the one in UnitPreDamaged) seems needless.

@GoogleFrog
Copy link
Contributor

My concern is that this PR seems to bound all fall damage.

I like most of the whitespace changes, think that all the space before = {} is a bit much, but am neutral on it. I don't like the two extra newlines for line wrap.

Comment on lines +198 to +213
-- Cap damage to landing weapon damage if available
if maxLandingDamage[unitDefID] then
otherDamage = math.min(otherDamage, maxLandingDamage[unitDefID])
else
-- Fallback cap for units without landing weapons
local unitHealth = UnitDefs[unitDefID].health
otherDamage = math.min(otherDamage, unitHealth * 0.2) -- Cap at 20% of max health
end

if maxLandingDamage[otherUnitDefID] then
myDamage = math.min(myDamage, maxLandingDamage[otherUnitDefID])
else
-- Fallback cap for units without landing weapons
local otherUnitHealth = UnitDefs[otherUnitDefID].health
myDamage = math.min(myDamage, otherUnitHealth * 0.2) -- Cap at 20% of max health
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-pasted code and also there's a third copy at line 361. How about

local function CapLandingDamage(damage, unitDefID)
		if maxLandingDamage[unitDefID] then
			damage = math.min(damage, maxLandingDamage[unitDefID])
		else
			-- Fallback cap for units without landing weapons
			local unitHealth = UnitDefs[unitDefID].health
			damage = math.min(damage, unitHealth * 0.2) -- Cap at 20% of max health
		end
end

and then this chunk could become just

		-- Cap damage to landing weapon damage if available
		otherDamage = CapLandingDamage(otherDamage, unitDefID)
		myDamage = CapLandingDamage(myDamage, otherUnitDefID)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants