Skip to content

Commit

Permalink
Fix Starlight aiming. Fixes #3716.
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogleFrog committed Aug 29, 2019
1 parent 3a29346 commit b109f4f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Objects3d/starlight.dae
Expand Up @@ -2075,7 +2075,7 @@
<node id="SatelliteMount" name="SatelliteMount" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 65.62811 0 0 0 1</matrix>
<node id="SatelliteMuzzle" name="SatelliteMuzzle" type="NODE">
<matrix sid="transform">1 0 0 0 0 -1 -1.50996e-7 0 0 1.50996e-7 -1 -19.5185 0 0 0 1</matrix>
<matrix sid="transform">1 0 0 0 0 -1 0 0 0 0 -1 -19.5185 0 0 0 1</matrix>
</node>
<node id="Satellite" name="Satellite" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
Expand Down
2 changes: 1 addition & 1 deletion Objects3d/starlight_satellite.dae
Expand Up @@ -439,7 +439,7 @@
<node id="Root" name="Root" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
<node id="SatelliteMuzzle" name="SatelliteMuzzle" type="NODE">
<matrix sid="transform">1 0 0 0.003364637 0 -1 1.50996e-7 -0.02567132 0 -1.50996e-7 -1 -7.261059 0 0 0 1</matrix>
<matrix sid="transform">1 0 0 0 0 -1 0 0 0 0 -1 -7.261059 0 0 0 1</matrix>
</node>
<node id="Satellite" name="Satellite" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 -7.2 0 0 0 1</matrix>
Expand Down
22 changes: 16 additions & 6 deletions scripts/mahlazer.lua
Expand Up @@ -106,6 +106,14 @@ local function CallSatelliteScript(funcName, args)
end
end

local HEADING_TO_RAD = 1/32768*math.pi
local function GetDir(checkUnitID)
local heading = Spring.GetUnitHeading(satUnitID)
if heading then
return math.pi/2 - heading*HEADING_TO_RAD
end
end

local isFiring = false
local function SetFiringState(shouldFire)
if isFiring == shouldFire then
Expand All @@ -125,11 +133,11 @@ function Undock()

if state == DOCKED then
for i = 1, 4 do
Turn(DocksClockwise[i] ,z_axis,math.rad(-42.5),1)
Turn(DocksClockwise[i] ,z_axis,math.rad(-42.5),1)
Turn(DocksCounterClockwise[i],z_axis,math.rad( 42.5),1)

Turn(ActuatorBaseClockwise[i],z_axis,math.rad(-86),2)
Turn(ActuatorBaseCCW[i] ,z_axis,math.rad( 86),2)
Turn(ActuatorBaseCCW[i] ,z_axis,math.rad( 86),2)

Turn(ActuatorMidCW [i],z_axis,math.rad( 53),1.5)
Turn(ActuatorMidCCW[i],z_axis,math.rad( 53),1.5)
Expand Down Expand Up @@ -236,10 +244,10 @@ function TargetingLaser()
if not isStunned then
--// Aiming
local dx, _, dz = Spring.GetUnitDirection(satUnitID)
if dx then
local otherCurrentHeading = GetDir(satUnitID)
if dx and otherCurrentHeading then
local currentHeading = Vector.Angle(dx, dz)

local aimOff = (currentHeading - wantedDirection + math.pi)%(2*math.pi) - math.pi
local aimOff = (otherCurrentHeading - wantedDirection + math.pi)%(2*math.pi) - math.pi

if aimOff < 0 then
if aimOff < -ROTATION_SPEED then
Expand Down Expand Up @@ -377,7 +385,9 @@ function script.AimWeapon(num, heading, pitch)

wantedDirection = currentHeading - heading + math.pi

CallSatelliteScript('mahlazer_AimAt',pitch + math.pi/2)
pitchFudge = (math.pi/2 + pitch)*0.999 - math.pi/2

CallSatelliteScript('mahlazer_AimAt', pitchFudge + math.pi/2)
Turn(SatelliteMuzzle, x_axis, math.pi/2+pitch, math.rad(1.2))
WaitForTurn(SatelliteMuzzle, x_axis)

Expand Down

0 comments on commit b109f4f

Please sign in to comment.