How do I detect velocity only for movement & not jumping?

local MovementVelocity = Character:WaitForChild("HumanoidRootPart").Velocity * Vector3.new(1,0,1)

The code above demonstrates a simple solution to calculate a player’s movement velocity on a flat surface by ignoring the Y-axis component of the velocity. This works well for basic systems.

However, I’m encountering an issue where this code does not accurately account for movement on sloped surfaces (such as wedges). When the player is moving along a tilted surface, the Y-axis velocity changes due to the incline, even though the player isn’t jumping or falling. This results in incorrect values, as the Y component becomes part of the horizontal movement.

In summary, I want to calculate the player’s movement velocity without including the additional velocity caused by jumping or falling, but still account for movement on sloped surfaces.

Not entirely sure how feasible this would be, but if you check the FloorMaterial of the humanoid you can determine if they are in the air or on the ground.

local OnTheGround = Character.Humanoid.FloorMaterial ~= Enum.Material.Air
local MovementVelocity
if OnTheGround then
    MovementVelocity = Character:WaitForChild("HumanoidRootPart").Velocity
else
    MovementVelocity = Character:WaitForChild("HumanoidRootPart").Velocity * Vector3.new(1,0,1)
end

or as a single line:

local MovementVelocity = Character:WaitForChild("HumanoidRootPart").Velocity * Vector3.new(1,Character.Humanoid.FloorMaterial == Enum.Material.Air and 0 or 1,1 )
2 Likes

Ah! This seemed to do the trick, thank you dearly SeargentAUS!

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