Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Knowing the Humanoid is moving forwards, backwards, etc? (Solved)

Asked by
pidgey 548 Moderation Voter
4 years ago
Edited 4 years ago

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!

0
what TheluaBanana 946 — 4y
0
Depends really what you mean. Do you mean is the character moving north, south, west or east? Or is the character moving forward, backward, etc relative to the camera. Or relative to a certain part? Edit: Btw in roblox character is always facing the direction he/she is walking, unless in first person mode. sleazel 1287 — 4y

2 answers

Log in to vote
0
Answered by
pidgey 548 Moderation Voter
4 years ago

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!

Ad
Log in to vote
0
Answered by
JedDevs 20
3 years ago

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))

Answer this question