How do I change walk animation depending on walkspeed

Hi,

I’m making a local script that handles the players speed. One thing I am trying to do is, if the player is sprinting, they gain speed and when they reach a walkspeed of 17, their animation changes to a running animation smoothly (smooth as in weight animation). Problem is I don’t know how to change the walk animation in a script.

Here’s what I am working with:

function Run()
	local RelativeDirection = math.round(Humanoid.MoveDirection:Dot(Camera.CFrame.LookVector))
	
	if RelativeDirection ~= 1 then -- must be going foward in order to run
		return
	end
	
	if not Running then
		Running = true
	end
	
	if not RunLerp then
		RunLerp = RunService.RenderStepped:Connect(function()	
			print("Running")
			--Humanoid.WalkSpeed = lerp(Humanoid.WalkSpeed, RunningSpeed, 0.05) -- increment (looks awkward without run anim)
			
			--if Humanoid.WalkSpeed > 17 then
			--	-- switch walk animation to run animation
			--end
		end)
	end
end
1 Like

Just put the changing animation segment into the UserInputService script that triggers the run function. I don’t see a reason why you have to make it specifically if they are above 17 speed.

It doesn’t match the hands when you are full speed, I am using procedural footplant so it doesn’t look pretty at all.

I even have it so the walk animation adjusts to speed, so all I need to do is make the arms swing higher (which is what the animation does)

Also can you show me what you mean

Still need help with this! @EVERYONE

Solved:

In roblox’s default animate script, I replaced run value with my anim and replace a function to this:

function onRunning(speed) -- TODO: fix speed on walkspeed change
	speed /= getRigScale()
	
	if speed > 0.01 then
		print("Walking")
		playAnimation("walk", 0.1, Humanoid)
		if currentAnimInstance then
			setAnimationSpeed(speed / 14.5)
			--print(speed / 10)
		end
		pose = "Running"
	else
		
		if emoteNames[currentAnim] == nil then
			playAnimation("idle", 0.1, Humanoid)
			pose = "Standing"
		end
	end
	
	if speed > 17 then
		playAnimation("run", 0.1, Humanoid)
		print("Sprinting")
	end
end

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