Custom walking/idle animations are not working as intended

i’m replacing the default character animate script in my game to make it easier to modify. I believe the running event works properly, so I think the problem is in the function i use to play the animation.
This is what I used:

playAnim = function(animID)
	animation.AnimationId = "rbxassetid://"..animID
	local track = animator:LoadAnimation(animation)
	track:Play()
	return track
end

hum.Running:Connect(function(speed)
	if speed > 0 then
		print("running")
		local track = playAnim(animID_run)
	else
		print("idled")
		local track = playAnim(animID_idle)
	end
end)


despite the print statements clearly showing up, the running animation does not stop playing.

The walk animation has an animation priority of Movement, and the idle has the Idle priority.

What should I fix in my code or animations to resolve the issue?

You need to save both tracks separately outside of the function (starting line), and play it with a weight of 0.001 (do NOT go lower than this, and do NOT stop neither animations)

And when the character starts walking, adjust the walk animationtrack weight to 1, and set the idle animationtrack weight to 0.001, and vice versa

If you set the weight to 0, the animation will not replicate, due to how Roblox animator works

Modified code (might contain errors as i wrote this on mobile)

playAnim = function(animID)
	animation.AnimationId = "rbxassetid://"..animID
	local track = animator:LoadAnimation(animation)
        track:Play()
	return track
end

local walktrack = playAnim(animID_run)
local idletrack = playAnim(animID_idle)

hum.Running:Connect(function(speed)
	if speed > 0 then
		walktrack:AdjustWeight(1,0.1)
                idletrack:AdjustWeight(0.001,0.1)
	else
                walktrack:AdjustWeight(0.001,0.1)
                idletrack:AdjustWeight(1,0.1)
	end
end)

what does weight do? I’ve heard of the name before, but I don’t know how to use it.

It’s basically the lerp for animations, if you rotate an arm in an animation by 90 degrees and the weight is 1, then it will rotate that arm the full 90 degrees, but if the weight is 0.5, then that arm will be rotated 45 degrees

is there a way I can allow each animation to restart every time it idles/starts moving? I am okay with taking a completely different approach to playing the animations if needed.

you can do AnimationTrack.TimePosition = 0 to reset the animation, when i make running and walking animation i always avoid stopping the animations because Roblox is kind of… tricky

1 Like

after trying this code out, the walk animation becomes the only animation which plays.

I have just realized, on the function, it does animation.AnimationId, straight away, without creating a new one… are you reusing the same animation Instance?

local function playAnim(animID)
	local anim = Instance.new("Animation")
	anim.AnimationId = "rbxassetid://" .. animID
	local track = animator:LoadAnimation(anim)
	track:Play()
	return track
end

local walktrack = playAnim(animID_run)
local idletrack = playAnim(animID_idle)

hum.Running:Connect(function(speed)
	if speed > 0 then
		walktrack:AdjustWeight(1, 0.1)
		idletrack:AdjustWeight(0.001, 0.1)
	else
		walktrack:AdjustWeight(0.001, 0.1)
		idletrack:AdjustWeight(1, 0.1)
	end
end)

(Updated Code)

1 Like

I didn’t know that could cause issues! solved!

1 Like

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