Skip to content

Commit

Permalink
Implement Terminal phase for missiles
Browse files Browse the repository at this point in the history
- Seraphim missiles slow down as they approach the target
- Aeon missiles zigzag less near the target so that they can hit, except Torrent
  • Loading branch information
lL1l1 committed Feb 19, 2024
1 parent ff78c11 commit 0005bb9
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 8 deletions.
1 change: 0 additions & 1 deletion lua/sim/projectiles/aeon/AMissileSerpentineProjectile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ AMissileSerpentineProjectile = ClassProjectile(SingleCompositeEmitterProjectile,
local blueprintPhysics = self.Blueprint.Physics
local radius = 0.105 * (blueprintPhysics.MaxSpeed + blueprintPhysics.MaxSpeedRange)
self:SetCollisionShape('Sphere', 0, 0, 0, radius)

self.MoveThread = self.Trash:Add(ForkThread(self.MovementThread, self))
end,

Expand Down
56 changes: 52 additions & 4 deletions lua/sim/projectiles/components/TacticalMissileComponent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@

local SemiBallisticComponent = import("/lua/sim/projectiles/components/semiballisticcomponent.lua").SemiBallisticComponent

local MathAbs = math.abs

---@class TacticalMissileComponent : SemiBallisticComponent
---@field TerminalTime number # How long before the terminal phase starts, in seconds. Default is 1/4 of the total glide time.
---@field TerminalDistance number # How far away the terminal phase starts, overrides TerminalTime.
---@field TerminalSpeed number # MaxSpeed of the missile in the terminal phase.
---@field TerminalZigZag number # MaxZigZag of the missile in the terminal phase. Default is 0.5.
TacticalMissileComponent = ClassSimple(SemiBallisticComponent) {

TerminalZigZag = 0.5,

---@param self TacticalMissileComponent | Projectile
MovementThread = function(self, skipLaunchSequence)
Expand Down Expand Up @@ -88,12 +96,52 @@ TacticalMissileComponent = ClassSimple(SemiBallisticComponent) {
self:SetTurnRate(glideTurnRate)
end

-- reduce the maximum zig zag frequency halfway so that they're unlikely to miss targets
WaitTicks((0.75 * glideTime + 0.1) * 10)
self:ChangeMaxZigZag(0.5)
local terminalTime = self.TerminalTime or glideTime * 0.25
local terminalDistance = self.TerminalDistance
local terminalSpeed = self.TerminalSpeed
local terminalZigZag = self.TerminalZigZag

local maxSpeed = blueprintPhysics.MaxSpeed
local accel = blueprintPhysics.Acceleration

if terminalDistance then
terminalTime = terminalDistance / (terminalSpeed or maxSpeed)
end

-- Changing the max speed below the current speed decelerates the projectile in 2 ticks.
-- Instead, create a smoother deceleration based on the projectile's actual acceleration.
if terminalSpeed then
local accelTime = MathAbs(maxSpeed - terminalSpeed) / accel

-- The glide time is based on max speed, but the terminal phase is based on terminal speed,
-- so we have to convert to the common variable of distance
-- and then back into time by dividing by max speed.
local accelDist = MathAbs((terminalSpeed * terminalSpeed - maxSpeed * maxSpeed) / 2 / accel)
local timeBeforeTerminal = glideTime - terminalTime * terminalSpeed / maxSpeed - accelDist / maxSpeed
-- Wait until the projectile reaches the point where the terminal phase should start.
if timeBeforeTerminal > 0 then
WaitTicks(timeBeforeTerminal * 10)
end

-- We will be changing our velocity in the next Wait, so update the lifetime.
glideTime = accelTime + terminalTime
self:SetLifetime((glideTime + 3))

for t = 0.2, accelTime, 0.2 do
self:SetMaxSpeed(maxSpeed - (maxSpeed - terminalSpeed) * t/accelTime)
WaitTicks(3) -- This waits 2 ticks instead of 3 according to GetGameTick().
end
self:SetMaxSpeed(terminalSpeed)
else
WaitTicks((glideTime - terminalTime) * 10)
end

glideTime = terminalTime

self:ChangeMaxZigZag(terminalZigZag)

-- wait until we've allegedly hit our target
WaitTicks((0.25 * glideTime + 1) * 10)
WaitTicks((glideTime + 1) * 10)

-- then, if we still exist, we just want to stop existing. Therefore we find our way to the ground
-- target the ground below us slowly turn towards the ground so that we do not fly off indefinitely
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ local AMissileSerpentineProjectile = import("/lua/aeonprojectiles.lua").AMissile
AIFMissileSerpentine02 = ClassProjectile(AMissileSerpentineProjectile) {
FxWaterHitScale = 1.65,
}
TypeClass = AIFMissileSerpentine02
TypeClass = AIFMissileSerpentine02
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ AIFMissileTactical03 = ClassProjectile(AMissileSerpentine02Projectile) {
HeightDistanceFactor = 5,
MinHeight = 10,
FinalBoostAngle = 45,

TerminalZigZag = 5,
}
TypeClass = AIFMissileTactical03

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local TacticalMissileComponent = import('/lua/sim/DefaultProjectiles.lua').Tacti
---@class SIFLaanseTacticalMissile01 : SLaanseTacticalMissile, TacticalMissileComponent
SIFLaanseTacticalMissile01 = ClassProjectile(SLaanseTacticalMissile, TacticalMissileComponent) {

LaunchTicks = 6,
LaunchTicks = 4,
LaunchTicksRange = 1,
LaunchTurnRate = 8,
LaunchTurnRateRange = 1,
Expand All @@ -38,6 +38,9 @@ SIFLaanseTacticalMissile01 = ClassProjectile(SLaanseTacticalMissile, TacticalMis
FinalBoostAngle = 12,
FinalBoostAngleRange = 2,

TerminalSpeed = 20,
TerminalDistance = 10,

---@param self SIFLaanseTacticalMissile01
OnCreate = function(self)
SLaanseTacticalMissile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ SIFLaanseTacticalMissile02 = ClassProjectile(SLaanseTacticalMissile, TacticalMis
FinalBoostAngle = 30,
FinalBoostAngleRange = 0,

TerminalSpeed = 20,
TerminalDistance = 15,

---@param self SIFLaanseTacticalMissile02
OnCreate = function(self)
SLaanseTacticalMissile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ SIFLaanseTacticalMissile03 = ClassProjectile(SLaanseTacticalMissile, TacticalMis
FinalBoostAngle = 30,
FinalBoostAngleRange = 0,

TerminalSpeed = 20,
TerminalDistance = 15,

---@param self SIFLaanseTacticalMissile03
OnCreate = function(self)
SLaanseTacticalMissile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ SIFLaanseTacticalMissile04 = ClassProjectile(SLaanseTacticalMissile, TacticalMis
FinalBoostAngle = 30,
FinalBoostAngleRange = 0,

TerminalSpeed = 13,
TerminalDistance = 30,

---@param self SIFLaanseTacticalMissile04
OnCreate = function(self)
SLaanseTacticalMissile.OnCreate(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ ProjectileBlueprint {
VelocityAlign = true,

ZigZagFrequency = 1,
MaxZigZag = 1
MaxZigZag = 1,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ SIFLaanseTacticalMissileCDR = ClassProjectile(SLaanseTacticalMissile, TacticalMi
FinalBoostAngle = 30,
FinalBoostAngleRange = 0,

TerminalSpeed = 13,
TerminalDistance = 30,

---@param self SIFLaanseTacticalMissileCDR
---@param inWater boolean
OnCreate = function(self, inWater)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ SIFLaanseTacticalMissileSCU = ClassProjectile(SLaanseTacticalMissile, TacticalMi
FinalBoostAngle = 30,
FinalBoostAngleRange = 0,

TerminalSpeed = 13,
TerminalDistance = 30,

---@param self SIFLaanseTacticalMissileSCU
---@param inWater boolean
OnCreate = function(self, inWater)
Expand Down

0 comments on commit 0005bb9

Please sign in to comment.