Get character's movement direction relative to itself

Apologies, what I want may not be clear from the information given.

Basically, I need a vector for the humanoid’s MoveDirection relative to the direction the character is facing.

What I mean is if the character is moving forward, the vector should be (0, 0, -1), backwards (0, 0, 1), etc. The GetMoveVector function in the ControlModule does not work for it, as i need the vector to be relative to where the HumanoidRootPart itself is facing, not the camera.

I have tried many suggestions, ranging from simple arithmetic to trigonometry, and none of them have given me a correct vector.

If you have any suggestions, I’d be glad to hear them.

1 Like

This might be incorrect math but it should be something similar to (Humanoid.MoveDirection - HRP.Direction)

local result = humanoid.MoveDirection - humanoidRootPart.Rotation

Ok, that might not work, but this will:

local result = humanoidRootPart.CFrame:VectorToObjectSpace(humanoid.MoveDirection)
4 Likes
local z = humanoidRootPart.CFrame.LookVector:Dot(humanoid.MoveDirection)

to discretize it:

z = if z > 0 then -1 else if z < 0 then 1 else 0

After some experimentation, this appears to be working as I wanted. Thank you.

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