So ive created this code that plays my animation. When im standing still the idle animation works fine, when i walk in a straight line the walking animation works fine.
But when i start turning it just freaks out, is there anybody that has experience with animations and knows how to fix this?
Please let me know
local WalkAnimation = script:WaitForChild("Walk")
local IdleAnimation = script:WaitForChild("Idle")
local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)
local humanoid = character.Humanoid
local WalkAnimationTrack = humanoid.Animator:LoadAnimation(WalkAnimation)
local IdleAnimationTrack = humanoid.Animator:LoadAnimation(IdleAnimation)
humanoid.Running:Connect(function(speed)
if speed <= 0.1 then
IdleAnimationTrack:Play()
WalkAnimationTrack:Stop()
elseif speed > humanoid.WalkSpeed / 2 then
WalkAnimationTrack:Play()
IdleAnimationTrack:Stop()
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Perhaps you can use humanoid:GetPropertyChangedSignal("MoveDirection") to check if the character is moving or not. If the MoveDirection is 0,0,0 then it’s not, if else then it is.
What if you stop the idle animation first, then play the walk animation?
Also, when your character turns, their speed probably drops below 0.1 so try raising it to if speed <= 0.5 to see if it makes a difference. If it does then keep decreasing it from 0.5 to 0.4 and then lower until the issue happens again so you know the limit.
your issue is that you are spam playing the animation
humanoid.Running:Connect(function(speed)
if speed <= 0.1 then
IdleAnimationTrack:Play()
WalkAnimationTrack:Stop()
elseif speed > humanoid.WalkSpeed / 2 then
if WalkAnimationTrack.IsPlaying == false then
WalkAnimationTrack:Play()
end
IdleAnimationTrack:Stop()
end
end)
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if humanoid.MoveDirection==Vector3.new(0,0,0) then
-- The character is Idle
else
-- The character is moving
end
end)