Skip to content

Commit

Permalink
Fix bombers missing during vertical movement (#6572)
Browse files Browse the repository at this point in the history
Fixes Lua assuming bomb XZ speed comes from unit XZ speed instead of unit XYZ speed
  • Loading branch information
lL1l1 authored Jan 31, 2025
1 parent 04c780a commit 3c08c25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/snippets/fix.6572.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6572) Fix bombers missing when bombing while changing altitude.
13 changes: 10 additions & 3 deletions lua/sim/weapons/DefaultProjectileWeapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local UnitGetVelocity = UnitMethods.GetVelocity
local UnitGetTargetEntity = UnitMethods.GetTargetEntity

local MathClamp = math.clamp
local MathSqrt = math.sqrt

---@class WeaponSalvoData
---@field target? Unit | Prop if absent, will use `targetPos` instead
Expand Down Expand Up @@ -203,9 +204,16 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
-- Get projectile position and velocity
-- velocity will need to be multiplied by 10 due to being returned /tick instead of /s
local projPosX, projPosY, projPosZ = EntityGetPositionXYZ(projectile)
local projVelX, _, projVelZ = UnitGetVelocity(launcher)
local projVelX, projVelY, projVelZ = UnitGetVelocity(launcher)

local targetPos
-- The projectile will have velocity in the horizontal plane equal to the unit's 3 dimensional speed
-- Multiply the XZ components by the ratio of the XYZ to XZ speeds to get the correct XZ components
local projVelXZSquareSum = projVelX * projVelX + projVelZ * projVelZ
local multiplier = MathSqrt((projVelXZSquareSum + projVelY * projVelY) / (projVelXZSquareSum))
projVelX = projVelX * multiplier
projVelZ = projVelZ * multiplier

local targetPos, _
local targetVelX, targetVelZ = 0, 0

local data = self.CurrentSalvoData
Expand Down Expand Up @@ -283,7 +291,6 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
if not targetPos then
-- put the bomb cluster in free-fall
local GetSurfaceHeight = GetSurfaceHeight
local MathSqrt = math.sqrt
local spread = self.AdjustedSalvoDelay * (self.SalvoSpreadStart + self.CurrentSalvoNumber)
-- default gravitational acceleration is 4.9; however, bomb clusters adjust the time it takes to land
-- so we convert the acceleration to time to add the spread and convert back:
Expand Down

0 comments on commit 3c08c25

Please sign in to comment.