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 bombers missing during vertical movement #6572

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
7 changes: 7 additions & 0 deletions lua/sim/weapons/DefaultProjectileWeapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
local projPosX, projPosY, projPosZ = EntityGetPositionXYZ(projectile)
local projVelX, _, projVelZ = UnitGetVelocity(launcher)

-- 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 = math.sqrt((projVelXZSquareSum + _ * _) / (projVelXZSquareSum))
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that the variable is being used, projVelY shouldn't be called _ anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_ gets reused:

targetVelX, _, targetVelZ = UnitGetVelocity(target)

targetVelX, _, targetVelZ = UnitGetVelocity(target)

Should it be initialized as a local here?

Copy link
Contributor

Choose a reason for hiding this comment

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

In the end, it's all for readability - here it's just indicating that a variable that needs to be there isn't used. Ideally, it'd be redefined every time so that the function can more easily pop its return values into sequential registers, but I don't recall if shadowed variables in Lua get their register slot freed.

projVelX = projVelX * multiplier
projVelZ = projVelZ * multiplier

local targetPos
local targetVelX, targetVelZ = 0, 0

Expand Down
Loading