Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Run animations backwards?

Asked by 8 years ago

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

1 answer

Log in to vote
2
Answered by 8 years ago

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 :)

0
Does using manual Keyframes (I mean, different positions for a same model in separate "Bodies") allow interpolation? And does it work backwards, similarly to this? TheArmoredReaper 173 — 8y
0
I'll post an answer for models fishguy100 135 — 8y
0
There, I edited it. If it helped you, feel free to upvote and mark this as answered fishguy100 135 — 8y
0
Thank you! TheArmoredReaper 173 — 8y
View all comments (2 more)
0
A better linear interpolation is (t - 1)*v0 + t*v1 as yours is slightly less precise and does not gaurentee that when t = 1 v1 is returned BlackJPI 2658 — 8y
0
Actually it does. fishguy100 135 — 8y
Ad

Answer this question