# How can I get the direction a player is walking?

I’m making R6 Strafing animate script made by me, what I’m trying to do is get the direction the player is walking either straight or diagonally, for example:
LeftFront, Front, RightFront, Right, RightBack, Back, LeftBack, Left.

The problem is that I don’t have the “formula” to get the diagonal direction, I tried in various ways, but none of it worked out because I’m a little too stupid for angles.

I’m trying to get it out of the relative direction of the HumanoidRootPart

``````HRP.CFrame:VectorToObjectSpace(Hum.MoveDirection)
``````
2 Likes

You could do `Character.PrimaryPart.CFrame.LookVector` to get direction, and maybe try to go from there.

You could have a table where the index is a vector3 direction and the value is a string like frontLeft.

Then round the velocity of humanoid.MoveDirection and index the table with it.

Im on my phone right now but when im on later ill give an example.

1 Like

Extremely late, but you can get the humanoid’s MoveDirection, it returns a Vector3 value (as I believe), and you can get what direction they’re walking in.

You can actually get the direction in several ways, I have tried 3 methods since not long ago I was recreating the movement system of Quake and CS:GO in Roblox with LinearVelocity, but this same one is not made with the Roblox humanoid.

Method 1: With Humanoid
In fact If your movement system uses Humanoid you can use this method:

``````function getMoveDirection( humanoid: Humanoid, rootPart: BasePart ) : Vector3
local forward_direction = rootPart.CFrame.LookVector;
local right_direction = rootPart.CFrame.RightVector;

local wishdir = forward_direction * humanoid.MoveDirection.Z + right_direction * humanoid.MoveDirection.X;

return wishdir.Unit;
end;

local wishdir = getMoveDirection( humanoid, rootPart );
``````

Method 2: With LinearVelocity
If you use LinearVelocity you can simply get the direction of the vectors in the “VectorVelocity” property.

Method 3: Only RootPart, Custom Movement System
Thanks to the lookVector you can obtain the direction in which the player is looking based on your personalized movement system.

2 Likes