# Accelerated Sprint

What are some ways to make the character accelerate at a slower rate than what is currently done?

I’ve attempted the only good method I could think of: manipulating WalkSpeed through the use of the Humanoid.Running event which returns the actual speed. I set a minimum WalkSpeed so it would stop going down after a certain value.
I need it to accelerate more slowly after a certain value.

2 Likes

What’s your use case? Sounds more like a friction-based thing you’re trying to achieve here.

Physics with respect to character mass. I created a body mass scalar value in the humanoid that certain abilities are based on. I wanted to create an “accelerated sprint” so that acceleration wasn’t close to instant.

But that’s a good point. The main reason the code wasn’t achieving was because the speed change after increasing the WalkSpeed was non-existant.

1 Like

Say, is there a way to get the actual speed of the character immediately?
The same variable given in Humanoid.Running?

After some quick testing, I have determined that the variable returned by the `Humanoid.Running` event is just the magnitude of the horizontal velocity of the humanoid root part of the character.

This can be verified by running the following in a LocalScript placed in StarterCharacterScripts:

``````local humanoid = script.Parent.Humanoid;
local root = script.Parent.HumanoidRootPart;

humanoid.Running:Connect(function(walkSpeed)
local horizontalVelocity = root.Velocity*Vector3.new(1, 0, 1);
print(horizontalVelocity.magnitude == walkSpeed, horizontalVelocity.magnitude, walkSpeed)
end)
``````

The output should always print `true`, followed by two numbers which are identical. Therefore, if you wanted to get the speed of the character without respect to the event trigger, then it would be as simple as multiplying the humanoid root part’s velocity by `Vector3.new(1, 0, 1)` as I have done in the code example above.

1 Like

Oh ok. That’s rather interesting. I had thought about the HumandRootPart.Velocity.Magnitude as being the actual speed of the character. However, I didn’t think it would exclude the vertical velocity. I’ll get back to ya tomorrow.

Yeah, the reason it excludes vertical component is for reasons like jumping or falling, which can give the character more speed than it would have by walking along a surface. Your character may still be considered running while jumping or falling, so including the vertical component in the computation would yield an inaccurate result.

A more technical way of describing the walk speed would be the magnitude of the cross product between the root part’s velocity and its up vector. As far as I know, characters are always oriented upright when walking, so the up vector will always point… well… up. If characters had the ability to walk at an angle, say up a slope or something, then it would be more proper (and just correct) to calculate the velocity using this definition, as opposed to multiplying it by a horizontal mask vector.

Here is the code modified with the alternate, more accurate definition.

``````local humanoid = script.Parent.Humanoid;
local root = script.Parent.HumanoidRootPart;

humanoid.Running:Connect(function(walkSpeed)
local directionalVelocity = root.Velocity:Cross(root.CFrame.UpVector) -- probably better definition
print(directionalVelocity.magnitude == walkSpeed, directionalVelocity.magnitude, walkSpeed)
end)``````

Why not just use TweenService to accelerate to a certain value and then create a new tween which is slower after that point?
I use tweens to manipulate speed and it works just fine.

2 Likes