I’m making a running engine but the major issue is that the character runs his animation while staying in place, heres a gif: https://i.gyazo.com/f10d12135879a5dc165a36fb109d1744.mp4
(yes the fox goes wiggly)
So far I have tried humanoid state types but from what I tried it haven’t worked.
Here is the script i used:
“Running” as a HumanoidState also includes when you’re standing still. You could check the default animation script to see how that handles running animations, or check if the Humanoid’s MoveDirection isn’t 0,0,0 before playing the animation.
input.InputBegan:Connect(function(key)
local k = key.KeyCode
if k== Enum.KeyCode.LeftShift and h:GetState() == Enum.HumanoidStateType.Running then
-- ...
end
end)
Is the animation looped? This is likely your problem.
Also, because it just plays an animation on running, if the animation still is playing when you let it go, it will look unnatural. If you want to fix that, stop the animation on InputEnded event if the animation is still playing with animation:Stop().
Using GetState in my cases have proven to be very unreliable if you want to make the character stop the animation when you’re still, I’d recommend the Running event and checking if the speed is 0.
Can you please give an example of how to do so? I checked the roblox developer site and still coludn’t really understand how to use it for the player to run while his speed is not 0
Checking for the velocity of the player’s HumanoidRootPart would suffice. Example:
local uis = game:GetService("UserInputService")
local character = game.Players.LocalPlayer.Character;
local root = character:WaitForChild("Humanoid");
local run = game:GetService("RunService");
run.RenderStepped:Connect(function(dt)
uis.InputBegan:Connect(function(inp, gpe)
if gpe then return; end
if not (root.Velocity.Magnitude > 0) then runAnim:Stop(); return; end;
if inp.KeyCode == Enum.KeyCode.K then
if runAnim.IsPlaying then return; end
if final.IsPlaying then return; end
runAnim:Play();
final:Play();
end
end)
uis.InputEnded:Connect(function(inp, gpe)
if gpe then return; end
if inp.KeyCode == Enum.KeyCode.K then
if runAnim.IsPlaying or final.IsPlaying then return; end
runAnim:Stop(); final:Stop();
end
end
end
this may not be the best method, but it works (haven’t tested it yet though)
If you mean how it looks unnatural because it doesn’t stop when you stop holding the shift button, you have to manually stop it with InputEnded event connected function as I said before.
I’ve experienced this issue before, the problem is that the animation still plays even when the player isn’t moving, which is clearly unwanted. So while my solution may not be the best or well-optimised, I’m pretty certain it’d work