Animation still sometimes continue after freezing it

Like the title states, after I freeze the animation by adjusting its speed to 0, it would still sometimes continue for a bit before actually freezing.

animTrack:GetMarkerReachedSignal("Parry"):Connect(function()
	sm.AddStatus(char, "parrying")
		
	animTrack:AdjustSpeed(0)
		
	local hbLoop

	hbLoop = hb:Connect(function(deltaTime)
		if parryTimer[char] > 0 then
			parryTimer[char] = math.max(0, parryTimer[char] - deltaTime)
			--print(parryTimer[char])
		else
			hbLoop:Disconnect()
			animTrack:Stop()
		end
			
		if sm.CheckStatus(char, "deflect") then
			sm.RemoveStatus(char, "deflect")
				
			parryTimer[char] = parryTime
				
			if currentAnim[char] == "right" then
				currentAnim[char] = "left"
				anim.AnimationId = rightAnim
			elseif currentAnim[char] == "left" then
				currentAnim[char] = "right"
				anim.AnimationId = leftAnim
			end

			local animTrack = hum:LoadAnimation(anim)

			animTrack:Play()
			animTrack:AdjustSpeed(parryAnimSpeed)
		end
	end)
end)

Here’s an overly simplified version of the code:

animTrack:GetMarkerReachedSignal("Parry"):Connect(function()
	animTrack:AdjustSpeed(0)
		
	task.wait(0.2)
		
	animTrack:Stop()
end)

PS: The animation marker isn’t at the end of the animation.

2 Likes

Another method you could use is to get the current TimePosition of the animTrack, then Stop it and when you want to start it up again, replay the same animTrack but set the TimePosition back to the last position before it was stopped.

Or maybe you can try to set the AdjustSpeed to (0.0) or (0.01)… the problem don’t seem to come from your script so there is no other solution to it unfortunatly.

1 Like

Oh wait, i noticed that you created a new track in your function, and it have the exact same name as your main track, maybe it come from there so the script is confused between the main track and the new track

animTrack:GetMarkerReachedSignal("Parry"):Connect(function()
    ...
    --Code
    ...
    local animTrack = hum:LoadAnimation(anim)
    animTrack:Play()
    animTrack:AdjustSpeed(parryAnimSpeed)
end)
1 Like

I’ve removed the section where the script creates a new track before, and the problem was still there. Also, could you show a code example of what you meant from the first reply?

Sure

local animTrackTime = nil
local animTrack = hum:LoadAnimation(anim)

animTrack:Play()
...
animTrackTime = animTrack.TimePosition
animTrack:Stop()
...
animTrack = hum:LoadAnimation(anim)
animTrack.TimePosition = animTrackTime 
animTrack:Play()

Also another solution would be to do a completely different animation…
like instead of pausing the current animation at a keyframe, you can made another animation in which the character is static and have the wanted pause… and inside the script instead of pausing the track you stop it and run a new one with the static animation in a looped mode.

(Reply to your code example) Ok, I kind of get it. But I don’t want to continue the animation from a certain point the next time I fire it, I just want to freeze it for a bit then stop it.

Alright, so this could be your solution

local animTrack = hum:LoadAnimation(MovingAnimation)
animTrack:Play()

animTrack:GetMarkerReachedSignal("Parry"):Connect(function()
	animTrack:Stop()
	
	local pausedAnimTrack = hum:LoadAnimation(PausedAnimation)
	pausedAnimTrack.Looped = true
	pausedAnimTrack:Play()

	hbLoop = hb:Connect(function(deltaTime)
		if ... then
			--print(parryTimer[char])
		else
			pausedAnimTrack:Stop()
		end
		
		if ... then
			local newAnimTrack = hum:LoadAnimation(anim)

			newAnimTrack:Play()
			newAnimTrack:AdjustSpeed(parryAnimSpeed)
		end
	end)
end)

I’ve just done something pretty similar to what you have above, but the problem is that there’s still a delay when “animTrack:Stop()” gets called. This results in the previous animation still running for a bit past the marker event before the new animation is played.

Can you add a new marker a bit before the Parry one to prevent this delay ?
Like if the delay is approximately 0.1s, add a new marker 0.1s before the Parry

That could work, but again, there’s only a delay sometimes. So the rest of the time, the animation stops before the time that I want it to.

Hmm okay, i have a lack of solution now, sorry :sweat_smile:
If the delay randomly happen no matter which method you use, i don’t know if you can really do something about it, especially if it come from Roblox backend and its natural client/server replication delay.

Thanks for your attempted help though.

1 Like

Did you tried to load animations on the Animator instead of the humanoid?
maybe it have less delay

Yes, I’ve just tried it by doing:

local animTrack = char.Character.Animator:LoadAnimation(anim)

But it still has the same delay.

A solution that I found was just adding the same frame of animation directly after the marker in the animation editor, so that even if there’s a delay, the animation would stop at the same position. It doesn’t work out 100% of the time and it makes the whole animation a bit lengthier, but it’s way better than before.

You could just extend this same frame time by a whole sec to keep the character in pause and prevent any delay time.
And in case you want to resume it, you can set the track TimePosition at the right keyframe when the character movements resume.

Something like that

–Character Movement [Parry] --Character Pause- […] Character Movement
v---------------------------v [Parry] v----------------------v […] v-----------------------v
0 - 0.25 - 0.5 - 0.75 - 1 [Parry] 1.25 - 1.5 - 1.75 - 2 […] 2.25 - 2.5 - 2.75 - 3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.