I've come up with a way that I'd like to handle animating in my game.
I created a table containing all the actions that need to be done in the animation with each key being a keyword telling the code what to animate to what target in what amount of time. I don't quite know how to implement this however.
Here is my animation sequence:
local reloadAnimationSequence = { RightArm = { CFrame.new() * CFrame.Angles(math.rad(90), 0, 0), 0.8 }, Delay = 0.5, -- Getting the mag. RightArm = { CFrame.new(), -- Replacing the mag 0.6 }, Delay = 0.1, -- Pulling the bolt LeftArm = { CFrame.new(-.2, .3, .5), 0.35 }, LeftArm = { CFrame.new(-.2, .3, .2), 0.2 }, LeftArm = { CFrame.new(), 0.25 } }
So basically, when the code looks through this sequence it should see the key "RightArm" and animate the right arm to RightArm[1]
which is the target CFrame in RightArm[2]
which is how long it takes to reach it's target.
"Delay" will tell the code to pause the script for that amount of time.
Is this even possible? If it is, how could I implement this?
Hey AZDev,
You should instead use an array of tables with the information in question. Observe:
local reloadAnimationSequence = { { RightArm = CFrame.new() * CFrame.Angles(math.rad(90), 0, 0); Duration = 0.8; Delay = 0.5; }; { RightArm = CFrame.new(); Duration = 0.6; Delay = 0.1; }; { RightArm = CFrame.new(-.2, .3, .5); Duration = 0.35; Delay = 0; }; { LeftArm = CFrame.new(-.2, .3, .2); Duration = 0.2; Delay = 0; }; { LeftArm = CFrame.new(); Duration = 0.25; Delay = 0; }; }
You might parse this as such:
for i, frame in ipairs(reloadAnimationSequence) do -- Assuming that you apply the CFrame to Welds here. local currentLeftC1 = leftArmWeld.C1; local currentRightC1 = rightArmWeld.C1; local duration = ((frame.Duration and frame.Duration > 0) and frame.Duration/10 or 0) for i = 1, 10 do leftArmWeld.C1 = (frame.LeftArm and currentLeftC1:lerp(frame.LeftArm, i) or leftArmWeld.C1) rightArmWeld.C1 = (frame.RightArm and currentRightC1:lerp(frame.RightArm, i) or rightArmWeld.C1) wait(duration) end wait(frame.Delay) end
Hopefully this helps. Have a good one, and best of luck with that FPS. c;
Cheers,
tkcmdr
Edit: Fixed duration oversight