So velocity.magnitude reads the speed of the player from the x,y,z and I don’t want it to read the y. Is there any way to do this?
2 Likes
Multiply the Y
component by 0:
(velocity*Vector3.new(1, 0, 1)).Magnitude
4 Likes
I’ll do you one better. Since this is essentially a vector2 you’re dealing with here, you can use the Pythagorean theorem to calculate the 2d distance of the velocity. This solution ends up being more performant than multiplying the vector’s y coordinate by 0, since it eliminates the need to do math operations to cut out the y, plus cuts down on how costly Magnitude is in general.
Here’s the equation:
local magnitude = math.sqrt(velocity.X^2 + velocity.Z^2)
11 Likes