What is humanoid.MoveDirection.magnitude?

I just saw a code today which makes the camera bobbing while a player is moving.
So an explanation on movedirection and it’s magnitude(distance) would be helpful :slight_smile:


MoveDirection tells you the direction of where the Humanoid is trying to walk to - like where you’re moving your character with the movement keys. For example, if you move your character along the positive X axis, your MoveDirection will be 1, 0, 0. If you move diagonally between the positive X and Z axes, your MoveDirection will be approximately 0.707, 0, 0.707.

The magnitude of MoveDirection describes its length. Since MoveDirection is a unit vector, its magnitude is equal to 1 always - unless it’s a zero vector (0, 0, 0).

With the camera bobbing, the magnitude of MoveDirection is used to know whether or not the player is moving around. Since the magnitude is always 1 (greater than 0) when MoveDirection is not a zero vector, we can find out when the player is moving to make the camera bob.


Im currently making a shift sprint system and it only executes when a player is moving , so can i use this movedirection to implement it???

Yes, you can use MoveDirection.Magnitude > 0 to check if the player is moving for your sprint script.


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