TL;DR - How can I make it so that if I play a tween while one is already playing, instead of canceling out the currently playing tween it “blends” them together?
Alright, little bit of context here.
I am trying to animate the landing gear of an airplane. There’s some specific mechanisms here at play, it’s motor6D, and I can’t just have every part of it retract with 1 tween, as parts will need to shift around a bunch.
Now, I thought “what if I played the next tween as the previous one was playing?” thinking that it was gonna “smooth out”, but turns out… It cancels out the tween that’s currently playing.
How can I make it so that instead of canceling out it “blends” the 2 tweens together? (As some sort of transition I guess?)
Here’s a picture of the landing gear, highlighted parts are the pivots for the motors.
You might want to consider just using an animation if you’re doing a complicated animation. Just add an animation controller on the server, name each part something unique (I think you need to do this at least), rig it up with motor6s, use the animation editor to make the animation, and then play it by loading the animation on the controller then using the :Play() function.
It should only cancel the tween if you’re trying to tween the same motor6 twice. Would it be possible to either: add a second motor6 there so it’s basically a double joint (then use separate tweens for each motor6) or just split the animation for the single motor6 into two tweens that don’t overlap?
If you want to have tweens that go over each other, you’ll generally need three things:
A first movement tween
A second movement tween
A weight value (for lerping between)
A tween to move the weight (or do it manually just like a tween would)
Here’s an example:
local targetInstance -- Your Instance
local propertyName -- The property name, probably C1 or C0
local target1Value = Instance.new("CFrameValue")
local target2Value = Instance.new("CFrameValue")
local weight = Instance.new("NumberValue")
-- Whatever your two tweens are
local tween1 = TweenService.Create(target1Value, TweenInfo.new(1), {Value = [Your Target]})
local tween2 = TweenService.Create(target2Value, TweenInfo.new(1), {Value = [Your Target]})
-- Customize the tween info to change how it fades between the stuff
local weightTween = TweenService:Create(weight, TweenInfo.new(1), {Value = 1})
local updateConnection
updateConnection = RunService.Heartbeat:Connect(function()
targetInstance[propertyName] = target1Value.Value:Lerp(target2Value.Value, weight.Value)
-- End the connection if all the tweens are done playing
if tween1.PlaybackState ~= Enum.PlaybackState.Playing and tween2.PlaybackState ~= Enum.PlaybackState.Playing and weightTween.PlaybackState ~= Enum.PlaybackState.Playing then
updateConnection:Disconnect()
end
end)
tween1:Play() -- Start your first animation
task.wait(1) -- Whatever the delay is for your second tween
tween2:Play()
weightTween:Play() -- Starts fading from tween1 to tween2