How do I get the speed of a part?

Sorry for the confusing title. What I am trying to do is get the general speed at which the part is moving at. For example if the part’s velocity is Vector3.new(5, -5, 5) the general speed of the part would be 15. math.abs(x) + math.abs(y) + math.abs(z)

However when I try to do that to my character by accessing the HumanoidRootPart velocity (yes I know about MoveDirection I can’t use that for this) I run into a problem. When moving at the same speed in different directions the general speed is inconsistent. Am I doing something wrong with the calculation?

10 Likes
local Velocity = HumanoidRootPart.Velocity.magnitude;
35 Likes

Oh wow, I never thought of it like that. Thanks for the quick reply.

4 Likes

Wow, I actually really needed this information too thanks, the humanoid Running event wasn’t working for what I needed, I wish I knew this sooner haha :sweat_smile:

1 Like

How can I check speed of one local axis of a part ?

local Velocity = (HumanoidRootPart.Velocity * Vector3.new(0,1,0)).Magnitude

Where 1 is the axis you want to monitor.

6 Likes

Or just HumanoidRotPart.Velocity.Y

1 Like

local Velocity = (HumanoidRootPart.Velocity * Vector3.new(1,0,0)).Magnitude
for checking speed of car
local Velocity = (HumanoidRootPart.Velocity * Vector3.new(0,0,1)).Magnitude
for checking helicopters speed of going sideways

am I right?

No, all the multiplication is doing is devaluing different axises for the .Magnitude calculation.

If you look at a plane then you can see that a car could move diagonally thus changing the X & Z velocities. So it would be pretty safe to ignore the Y Axis * Vector3.new(1,0,1) but if you were monitoring a rocket ship then how fast it is going up is probably the most import thing to you * Vector3.new(0,1,0)
cae8013f822398b7ad0258fab03f1088

3 Likes

What should I do if I only want to check the speed on the red local axis but not the speed on the green and blue one in flight

Please use AssemblyLinearVelocity instead of Velocity as it is deprecated

local Velocity = HumanoidRootPart.AssemblyLinearVelocity.Magnitude
9 Likes

this should be marked as the solution as the old one is deprecated and should be avoided for new stuff.

1 Like