Humanoid animation keeps stuttering when walking up terrain

I have walking animations that play when the humanoid is running, and stop when their not.
a pretty simple system that got a lot more complicated when terrain is introduced.

heres an example, the walking animation is looped and will only stop if the humanoid is no longer running:
robloxapp-20201022-1344327.wmv (1.9 MB)
this is the code used at the time of recording the video:

loadwalk = hum:LoadAnimation(walkanim)


hum.Running:Connect(function(speed)

if speed > 0 then
loadwalk:Play()
elseif speed <= 0 then
loadwalk:Stop()
end

end)

now Ive tried many things at this point.
ive tried checking of the humanoid is freefalling or landing as that seems to be happening when a character climbs terrain, but I couldnt get consistent results with this.
ive tried checking the humanoids movedirection instead, but that didnt work either.
ive even tried doing all of those above at the same time but it just made the stutter worse.
im at a loss on how to fix this, perhaps someone has had this issue and knows a workaround?

1 Like

The script makes the humanoid animations look bad to you basically, because you probably don’t like those animations. Have you checked for any red/orange underlines in any of your codes? Codes do not work with underlines under some script statements, due to them having to be exactly correct for the animatoon to be correct.

1 Like

Is the script running on the server on on local script?

See: Tweening model while also using AnimationController resulting in jittery movement

1 Like

scottie, Im confused as to what exactly your trying to say. if your saying the code has errors I assure you it does not.

jvdad, im using a custom animation that I made, its on a localscript.just to clearify this is for the players character, not a non humanoid npc so the animation is loaded on the humanoid, not an animation controller.

Does the animation look good, just like you want it, in the animation editor?

yes, if you look in the video notice that for terrain that is perfectly smooth the animation plays nice, what going on is that the running event thinks that when the character walks over uneven terrain, the character must not be walking anymore, so it stops the animation. but this isnt the case and this constant stop and starting is causing the stutter. I want to know how I can keep the animation going until the player actually stops walking.

Perhaps you could connect to the change state function and as soon as it detects a new (wrong) state, set it to the state you want (or kick the animation into play from where it left off)?

I wouldn’t use hum.Running to detect if the player is moving since that seems to trip multiple times during testing for me. try detecting humanoid states like jvdad suggested.

HumanoidStateType | Documentation - Roblox Creator Hub look into this for more info on humanoidstates

I found a solution that bypasses any humanoid state changes altogether, I just needed my old friend magnitude.

when the character is not moving an inch, its magnitude is less than 1, now for whatever reason magnitude is never a perfect 0 but that’s ok. when the player is physically moving at all, even just a little, the magnitude is bigger than 1. using this, I can play the animation when the player is moving around regardless of the terrain, and stop playing it when they officially stop moving.

here is the final result:

if walkanim then
loadwalk = hum:LoadAnimation(walkanim)

spawn(function()
while true do
wait()
print(char.Torso.Velocity.Magnitude)
if char and char:FindFirstChild("Torso") and char.Torso.Velocity.Magnitude >= 1 and loadwalk.IsPlaying == false then
loadwalk:Play()
elseif char and char:FindFirstChild("Torso") and char.Torso.Velocity.Magnitude < 1 then
loadwalk:Stop()
end
end
end)

end

end

Cool!

BTW If you want to do it that way, then it is best practice to use RunService (rather than while true do) as it is a built in high speed stepper and you don’t need spawn.

oh the spawn is for anything else I put below the code. I didn’t include the whole script as it wasn’t important to add. I know its a bit of a wierd way to run things below a while loop but it works for me.

Why are you using a while loop and not the Running Event?