Help with blending running and walking animations

Hi everyone!!!

I’m trying to make a sprinting system inspired by CRIMINALITY - by RVVZ (the most popular example I could think of that uses this kind of animation blending), there are many other games that do this similarly.

If you don’t know what I’m talking about, check out this video:


As you can see, whenever I enter the sprinting state, the running animation blends in smoothly.

Anyway, the reason I am so intrigued by Criminality’s sprint system is how the animation blending between the walking and running animations work. I’ve had a look at one script that someone made inspired by this, and I saw that they slightly edited the OnRunning function in the default Animate script to play the running animation if the player speed is higher than a set variable.

Credits to @5tihat for giving me a model showcase of a similar system, the code below is from that model but is slightly edited by me.

Code (in edited Animate script):

local MinRunSpeed = 18

function onRunning(speed)
	if speed > 0.01 and speed < MinRunSpeed then
		playAnimation("walk", 0.25, Humanoid)
		setAnimationSpeed(speed / 16)
		pose = "Walking"
	elseif speed >= MinRunSpeed then
		playAnimation("run", 0.25, Humanoid)
		setAnimationSpeed(speed / 16)
		pose = "Running"
	else
		if emoteNames[currentAnim] == nil then
			playAnimation("idle", 0.1, Humanoid)
			pose = "Standing"
		end
	end
end

There’s also another localscript paired with this for the sprint button (in StarterCharacterScripts):

local UserInput = game:GetService("UserInputService")
local Humanoid = script.Parent:WaitForChild("Humanoid")

local Input = Enum.KeyCode.LeftControl

UserInput.InputBegan:Connect(function(i, gp)
	if i.KeyCode == Input and gp == false then
		Humanoid.WalkSpeed = 22-- you can change this to sprint value to which one you want.
	end
end)

UserInput.InputEnded:Connect(function(i)
	if i.KeyCode == Input then
		Humanoid.WalkSpeed = 16 --default speed.
	end
end)

This system does not suit my needs properly, but has taught me more about how I would go about doing something like this! When I first read through the code in this model, I came up with an idea to only play the running animation if the player is running above the required speed and actually sprinting (which I could detect with attributes or modulescripts set from the sprinting script maybe)

I’ve tried making something like this before, but not in the way I imagined. What I did was edit the setRunSpeed function in the Animate script, changing the two properties called normalizedWalkSpeed and normalizedRunSpeed until finding a sweet spot, where the animation would blend to the running animation at a certain speed, and not even checking if the player is actually sprinting or not! Even then, the results from this method were often janky and did not look like intended. EW!

There has to be a better way, right?

If someone knows how to do this or about making a running system with blending between two animations, please help a bruda out!!

Thanks !!!

Sorry if I do not respond immediately, it’s currently 3 am for me lol!!

3 Likes

sorry for the bump, but I really need help with this, my post has gone 4 days unanswered and I’m starting to get desperate so please can someone help!!

In your case I would just change the animation’s transition speed before playing it:

AnimationTrack:Play(1) -- 1 second transition

Or you can just play around with AdjustWeight.

2 Likes

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