So I made a plane system similar to jailbreaks where the plane flies and lands on the runway. I wrote the spawning part so the plane spawns and then flies to the runway and lands. The problem is, that the plane instantly stops when it hits the landing node.
This is unrealistic since in real life it takes planes a few seconds for them to come to a halt. So I decided to gradually tween the speed down. I came across a problem. I’ve spent 30 minutes trying to fix this!
When I tween the speed, instead of slowing down, the plane just stops, when it should be taking 5 seconds for it to slow down!
Script:
local TweenService = game:GetService('TweenService')
local PlaneController = {}
PlaneController.__index = PlaneController
function PlaneController.new(planeModel,nodes)
assert(typeof(planeModel) == 'Instance')
assert(typeof(nodes) == 'Instance')
local self = setmetatable({},PlaneController)
self.Nodes = nodes
self.PlaneModel = planeModel
self.Node = 0
self.Speed = 50
return self
end
function PlaneController:TweenSpeed(num,speed)
local value = Instance.new('IntValue')
value:GetPropertyChangedSignal('Value'):Connect(function()
print('Changed value to '..value.Value)
self.Speed = value.Value
end)
local info = TweenInfo.new(
num,
Enum.EasingStyle.Quart,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(value,info,{Value = speed})
tween:Play()
tween.Completed:Wait()
print('Tween finished')
end
function PlaneController:Spawn()
print('Ran')
self.Plane = self.PlaneModel:Clone()
-- welding
local descendants = self.Plane:GetDescendants()
for i = 1,#descendants do
if descendants[i] ~= self.Plane.PrimaryPart and descendants[i]:IsA('BasePart') then
local weld = Instance.new('Weld')
weld.Name = 'PlaneWeld'
weld.Part0 = self.Plane.PrimaryPart
weld.Part1 = descendants[i]
weld.C0 = self.Plane.PrimaryPart.CFrame:inverse()
weld.C1 = descendants[i].CFrame:inverse()
weld.Parent = self.Plane.PrimaryPart
end
end
self.Plane.Parent = workspace.CargoPlane
self.Plane:SetPrimaryPartCFrame(self.Nodes.Node1:GetPrimaryPartCFrame())
wait()
self:Fly()
end
function PlaneController:Fly()
self.Node = self.Node + 1
local node = self.Nodes:FindFirstChild('Node'..self.Node)
if not node then
if self.Node ~= 8 then
self:DespawnPlane()
return
end
end
if self.Node == 8 then
wait(8)
warn('Complete')
self:Fly()
end
if self.Node == 7 then
self:TweenSpeed(5,0)
end
local distance = (self.Plane.PrimaryPart.CFrame.p - node:GetPrimaryPartCFrame().p).Magnitude
local Time = self:GetTime(distance)
local tweenInfo = TweenInfo.new(
Time,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local PlaneTween = TweenService:Create(self.Plane.PrimaryPart,tweenInfo,{CFrame = node:GetPrimaryPartCFrame()})
PlaneTween:Play()
wait(Time)
self:Fly()
end
function PlaneController:GetTime(distance)
return distance / self.Speed
end
function PlaneController:DespawnPlane()
self.Node = 0
self.Plane:Destroy()
self.Plane = nil
end
return PlaneController
Here is where I call the TweenSpeed function:
if self.Node == 7 then
self:TweenSpeed(5,0)
end
I feel as if there is a simple fix, but I just cannot find it!
Thanks!