I’m looking for a way to specifically figure out which direction a player is trying to direct their character, be it on keyboard, gamepad, or mobile. I’m NOT trying to figure out which direction they’re actually moving in.
Any of the solutions I’ve tried (Humanoid.MoveDirection, the lookVector of the HumanoidRootPart, etc.) return the direction the character is actually moving in at that point; this won’t work for my purposes because the way Humanoid rotation works is a smooth transition into the desired movement direction. I’m trying to figure out the raw input direction the player wants to go in.
I’ve done some research on this issue, but I’ve come up dry in my endeavors. Any guidance or pointing in the right direction would be very helpful!
Say if the player is on a keyboard and they’re inputting only the D key. I would want to be able to deduce that they’re inputting a direction that’s exactly 90 degrees to the right of wherever the camera is facing.
That on its own wouldn’t be very hard to figure out, but I’m searching for a solution that can work across keyboard and analog input.
This should work. Uses the camera cframe as well as the raw movement vector provided by the PlayerModule to get the real movement direction.
local Controller = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
function GetInputDirection()
local Direction = workspace.CurrentCamera.CFrame:VectorToWorldSpace(Controller:GetMoveVector())
return if Direction.X > 0 or Direction.Z > 0 then Vector3.new(Direction.X, 0, Direction.Z).Unit else Vector3.zero
end
This is closest to the solution I figured out, thank you! I ended up doing some sneaky things with placeholder CFrames, but I did end up using GetMoveVector in the process.