I need to know what direction the humanoid is moving in. I don't want to be using input, just the move direction of the humanoid (Humanoid.MoveDirection). I know that MoveDirection is a unit vector in world space, but how would one mathematically tell if that vector relative to another object (in my case, the character) is forwards, backwards, left, or right? I have tried using the VectorToObjectSpace function, but it's just confusing me because I'm getting completely unexpected results. A solution with some explanation on how the math works would be greatly appreciated. Thanks!
I made a solution. If I set the MoveDirection's space relative to the HumanoidRootPart, I can tell which way the humanoid is moving. (The humanoid can move left or right while the humanoidrootpart can still be facing the front of the camera because of lockcamera, firstperson, etc).
humanoid.RootPart.CFrame:VectorToObjectSpace(humanoid.MoveDirection) --Z --> front/back --X --> left/right
I don't think I explained the question thorough enough for others to understand, but thanks anyway guys!
The answer by @pidgey didn't work for me but this did:
local LocalPlayer = game.Players.LocalPlayer local Controls = require(LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"):WaitForChild("ControlModule")) local move = Controls:GetMoveVector() print("Moving left/right: ", math.floor(move.X)) print("Moving front/back: ", math.floor(move.Z))