Hi.
Since I had some bugs using a standard animation script, I decided to write my own.
So far, the script includes 3 animations: idle, walking and sprinting
And I have a question about how much my decision is correct.
I use RunService because I need to track several states to run the correct animation: WalkSpeed and MoveDirection.
uis.InputBegan:Connect(function(input,processed)
if not processed then
if input.KeyCode == Enum.KeyCode.LeftShift then
if humanoid.MoveDirection.Magnitude ~=0 then
humanoid.WalkSpeed = sprintSpeed
end
end
end
end)
uis.InputEnded:Connect(function(input,processed)
if not processed then
if input.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = walkSpeed
end
end
end)
rs.Heartbeat:Connect(function()
local humanoidMoveDirectionMagnitude = humanoid.MoveDirection.Magnitude
if humanoid.WalkSpeed == 16 and humanoidMoveDirectionMagnitude == 0 and not idle then
stopAnimations()
sprinting = false
idle = true
walking = false
idleTrack:Play()
elseif humanoid.WalkSpeed == 16 and humanoidMoveDirectionMagnitude ~= 0 and not walking then
stopAnimations()
sprinting = false
idle = false
walking = true
walkTrack:Play()
elseif humanoid.WalkSpeed == 30 and humanoidMoveDirectionMagnitude ~= 0 and not sprinting then
stopAnimations()
sprinting = true
idle = false
walking = false
sprintTrack:Play()
end
end)