I want to make it so the closing animation of a door starts from the last position of the opening animation before stopping it.
The problem is that the closing animation starts from the start (so there is a bit of a teleport)
Test.wmv (239.8 KB)
I have tried saving the time position of the previous animation and applying it to the new one but since the animations slow down near the end it is still not quite what I want. I don’t know what to do.
Here are the functions for opening and closing the doors.
function BowlerTrainClass:open_doors()
for i, Instance_ in pairs(self.Train:GetDescendants()) do
if Instance_.Name == 'Door' and Instance_:FindFirstChild('HumanoidRootPart') then
local AnimationController = Instance_.AnimationController
local Opening = Instance_.Opening
local Opened = Instance_.Opened
local OpeningTrack = AnimationController:LoadAnimation(Opening)
local OpenedTrack = AnimationController:LoadAnimation(Opened)
local Sound = Instance_.DoorSound
while wait() do
if OpeningTrack.Length ~= 0 then
break
end
end
local sound_length = Sound.TimeLength
local animation_length = OpeningTrack.Length
local ratio = animation_length / sound_length * 1.5
for j, Track in pairs(AnimationController.Animator:GetPlayingAnimationTracks()) do
Track:Stop()
end
OpeningTrack:Play()
Sound:Play()
OpeningTrack:AdjustSpeed(ratio)
OpeningTrack.Stopped:Connect(function()
OpenedTrack:Play()
end)
end
end
end
function BowlerTrainClass:close_doors()
for i, Instance_ in pairs(self.Train:GetDescendants()) do
if Instance_.Name == 'Door' and Instance_:FindFirstChild('HumanoidRootPart') then
local AnimationController = Instance_.AnimationController
local Closing = Instance_.Closing
local Closed = Instance_.Closed
local ClosingTrack = AnimationController:LoadAnimation(Closing)
local ClosedTrack = AnimationController:LoadAnimation(Closed)
local Sound = Instance_.DoorSound
while wait() do
if ClosingTrack.Length ~= 0 then
break
end
end
local sound_length = Sound.TimeLength
local animation_length = ClosingTrack.Length
local ratio = animation_length / sound_length * 1.5
for j, Track in pairs(AnimationController.Animator:GetPlayingAnimationTracks()) do
Track:Destroy()
end
ClosingTrack:Play()
Sound:Play()
ClosingTrack:AdjustSpeed(ratio)
ClosingTrack.Stopped:Connect(function()
ClosedTrack:Play()
end)
end
end
end
I appreciate your support.