Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I run through this animation sequence and perform the actions specified?

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?

2 comments

0

Why not use roblox's animations?

0

Because ROBLOX animations, and the editor are buggy af. @RubenKan

1 answer

✓ Accepted answer

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

2 comments

0

I actually just noticed something. I don't think this will work for what I am doing. I won't just be animating arms. I'll be animating multiple joints. ie The Motor6D for the bolt, the magazine on the gun, etc. The sequence tells the code what to animate. Not just the target and duration.

0

Okay, I've made a few modifications and added the KeyWord into the array. Basically, certain keywords will tell the function what to animate. ie if the key is "Bolt" it will animate the C1 of the motor6d connected to the bolt.

This discussion is preserved as it was. New answers, comments, and votes are closed.