Animation sequences - how to properly do them?

Hi guys.
I’m in need to make situational animations (in my case for sword).
I want to make such system:

  1. Holding (a bit shaking it)
  2. Slashing from right to left
  3. Slashing from left to right (not just reversed but completely diffirent)
  4. Going back to holding

And this should go with the following loop:

1 + LMB Click -> 2
2 + LMB Hold -> 3
2 + No LMB Hold -> 1
3 + LMB Hold -> 2
3 + No LMB Hold -> 1

System seems not hard, but I have met some problems:

  1. How this should be created in terms of Animation Instances? Each piece of animation as diffirent animation, or one animation containing everything?
  2. What if user has ping? Animation will just end, or in case of one animation containing everything - go further and either go slash further or go hold.

So if it’s just a repetitive sequence with no other animation that need to run in between I suggest you make it one animation and add animationEvents if you need to create hitboxes or vfx. Also as long as you run the animation on the client side latency won’t be an issue.

here I’ll give you some idea of how you can do this

  1. You want the Animation for idle pose, Slash 1 and Slash 2
  2. and of course Your sword! try put all the animation in the place you can easily access

image

Now for the coding part
first we making so when the player equip the tool. the idle animation play

llocal Sword = script.Parent
local AnimationFolder = Sword.Animations

local player
local Humanoid
local Animator

local SlashTrack
local IdleTrack
local SlashCount = 1

Sword.Equipped:Connect(function()
	player = Sword.Parent
	Humanoid = player:WaitForChild("Humanoid")
	Animator = Humanoid:WaitForChild("Animator")
	IdleTrack = Animator:LoadAnimation(AnimationFolder.Idle)
	IdleTrack:Play()
end)

Sword.Unequipped:Connect(function()
	IdleTrack:Stop()
end)

image
Look! We now have a custom idle pose which all the slash animation will return to

now to make the sword slashing we just need to use .Activated function but that will just swing the sword normally, we don’t do that here!


Sword.Activated:Connect(function()
	if Debounce then return end
	Debounce = true
	SlashTrack = Animator:LoadAnimation(AnimationFolder["Slash "..SlashCount])
	SlashTrack:Play()
	wait(SlashTrack.Length)
	Debounce = false
	if SlashCount == 1 then
		SlashCount = 2
	else
		SlashCount = 1
	end
end)


Now we slashing!

but you may notice that the animation feel a little stiff and you can’t really do a slash combo with this
so let’s change that with GetMarkerReachedSignal
now what I didn’t tell you before is I put some animation event for use later while making animation for the sword

We’ll set debounce to false when it reached “Finish” marker so the sword won’t go back to the original pose before another slash is done this will replace wait()

Sword.Activated:Connect(function()
	if Debounce then return end
	Debounce = true
	SlashTrack = Animator:LoadAnimation(AnimationFolder["Slash "..SlashCount])
	SlashTrack:Play()
	SlashTrack:GetMarkerReachedSignal("Finish"):Connect(function()
		Debounce = false
	end)
	if SlashCount == 1 then
		SlashCount = 2
	else
		SlashCount = 1
	end
end)


Now we Slashing! 2.0 without an anoying pause between animation

Fully script
local Sword = script.Parent
local AnimationFolder = Sword.Animations

local player
local Humanoid
local Animator

local SlashTrack
local IdleTrack
local SlashCount = 1
local Debounce = false

Sword.Equipped:Connect(function()
	player = Sword.Parent
	Humanoid = player:WaitForChild("Humanoid")
	Animator = Humanoid:WaitForChild("Animator")
	IdleTrack = Animator:LoadAnimation(AnimationFolder.Idle)
	IdleTrack:Play()
end)

Sword.Unequipped:Connect(function()
	IdleTrack:Stop()
end)

Sword.Activated:Connect(function()
	if Debounce then return end
	Debounce = true
	SlashTrack = Animator:LoadAnimation(AnimationFolder["Slash "..SlashCount])
	SlashTrack:Play()
	SlashTrack:GetMarkerReachedSignal("Finish"):Connect(function()
		Debounce = false
	end)
	if SlashCount == 1 then
		SlashCount = 2
	else
		SlashCount = 1
	end
end)

Feel free to ask me if you have further question

Ps.: (I forgot to talk about another Animation Event which is call “Hit” but that is for creating a hitbox, in this post I’m only cover the animation)

2 Likes

Thanks for such big explanation! I’ll reply when I’ll try what you suggested myself. Thanks!

1 Like

So I did it… But issue I was aware of has been showed:


So, on client it looks good and smoothly, but on server there’s flickering animation. How I can solve this? (Also I know that this animation is really really far from being good, but I used it as fast prototype)