-
Notifications
You must be signed in to change notification settings - Fork 217
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
base: master
Are you sure you want to change the base?
Conversation
|
||
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 + |
There was a problem hiding this comment.
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.
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 |
-- 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 |
There was a problem hiding this comment.
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)
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.