How can i prevent a linearvelocity from being faster whilst moving diagonally?

i currently have a linearvelocity that accelerates the player forward when theyre in the air, the problem with this is how if they move diagonally, they move significantly faster than how they would while moving straight forward.

ex:

External Media

code:

Velocity.VectorVelocity = Humanoid.MoveDirection * 100
1 Like

Hi!! When a player moves diagonally, the MoveDirection vector is the result of combining two directions (forward + sideways), this will cause the overall magnitude of the vector to be greater (because it is a sum) than if the player were moving in a straight direction. You should normalize the MoveDirection vector, it will make sure that its magnitude is always 1, regardless of the direction.

Velocity.VectorVelocity = Humanoid.MoveDirection.Unit * 100

all of the axes in the movedirection vector are already capped at 1 so theres no difference

Yeah, individual components are caped at 1. But when moving diagonally the X and Z axes contribute to the final velocity resulting in a magnitude greater than 1.

Example, moving forward might give a MoveDirection of (0, 0, 1) with a magnitude of 1

But moving diagonally (forward-right for example) might give a MoveDirection of (1, 0, 1) making the magnitude of this vector a √2. So when you multiply by the speed factor it will make diagonal movement faster.

using .Unit still doesnt change anything tho, it will still contribute to a value greater than 1

I would avoid move direction altogether. You can accelerate them based on the direction they are looking. This is a much better system because it will accelerate them at the same speed regardless of the direction. You can learn how to do something like this in this article.

I am not supposed to be making the scripts for people. You need to learn how to do this yourself so you can understand how it works.

i solved this myself js forgot to mark it as solved