-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuidedBombVel.lua
More file actions
33 lines (27 loc) · 1.19 KB
/
Copy pathGuidedBombVel.lua
File metadata and controls
33 lines (27 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
behaviour("GuidedBombVel")
function GuidedBombVel:Start()
self.projectile = self.targets.projectile.GetComponent(Projectile)
if self.projectile == nil or not self.projectile.isTargetSeekingMissileProjectile then
self:DestroyScript()
return
end
self.syncCount = 2 -- Number of updates to sync velocity with killCredit
self.updateCounter = 0
-- Apply initial velocity from the firing vehicle
if self.projectile.killCredit then
self.projectile.velocity = self.projectile.killCredit.velocity * 1
local inheritedSpeed = self.projectile.velocity.magnitude
end
end
function GuidedBombVel:FixedUpdate()
if self.updateCounter < self.syncCount then
-- Keep syncing velocity with killCredit for the first 3 updates
if self.projectile.killCredit then
self.projectile.velocity = self.projectile.killCredit.velocity * 1
end
self.updateCounter = self.updateCounter + 1
end
-- Simulate gravity by applying a downward force
local gravity = Vector3(0, -9.81, 0) -- Gravity vector, adjust magnitude if needed
self.projectile.velocity = self.projectile.velocity + gravity * Time.fixedDeltaTime
end