Is it possible to run an Animation backwards? I made an unsheathing animation, but do not want to make it again in reverse (the last position is a bit hard to recreate...)
Thanks in advance!
TheArmoredReaper
I would make animations with CFrames and store them in a table instead of using a plugin. If you do that, this is how you can play it backwards:
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Torso = Character:WaitForChild("Torso") local RightArm = Torso:WaitForChild("Right Shoulder") local AnimationTable = {} for I = 1,40 do local C0 = RightArm.C0 * CFrame.fromAxisAngle(Vector3.new(1,1,0),math.rad(45)) table.insert(AnimationTable,C0) end
Now to play the animation backwards you would do:
for I = #AnimationTable,1,-1 do RightArm.C0 = AnimationTable[I] wait() end
Of course, you would have to change a bit to make it like you desire but I hope this points you in the right direction.
REASON WHY THIS WORKS:
We made a table with CFrames so that it can be read backwards and thus play the animation backwards. In the plugin, you cannot play animations backwards but making animations via script makes it easier to play it backwards without remaking it.
To do it with models you basically do the same thing but more along these lines:
local Part = workspace.Part -- Change to the part being moved local EndPos = workspace.End.CFrame -- Change to the CFrame the part ends at local AnimTable = {} local Iterations = 50 -- Change to how many steps it takes the part to get to it's destination for I = 1,Iterations do table.insert(AnimTable,Part.CFrame:lerp(EndPos,I/Iterations) end
To play it backwards:
for I = #AnimTable,1,-1 do Part.CFrame = AnimTable[I] end
To play it forwards:
for I = 1,#AnimTable do Part.CFrame = AnimTable[I] end
Oh and for future reference, lerp(Linear Interpolate) is basically this:
local function Lerp(v0,v1,t) return v0 + (v1 - v0) * t end
I hope this helps you :)