It’s hard to explain this. So with the usual WASD keybinds, you can hold two at once, such as W+D to go diagonal.
I want to check when a player is moving straight forward, but not diagonal. Is there a way to check this? (please make it be able to work on both mobile and computer.)
This should work for you:
local RunService = game:GetService("RunService")
local PlayerService = game:GetService("Players")
local player = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera
local update = function(deltaTime)
local character = player.Character
if not character then return end
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then return end
if humanoid.MoveDirection.Magnitude > 0 then
local relativeMoveVector = (camera.CFrame:VectorToObjectSpace(humanoid.MoveDirection) * Vector3.new(1, 0, 1)).Unit
if relativeMoveVector.Z < -.9 then
print("forward")
end
end
end
RunService.Heartbeat:Connect(update)
Just put this in a local script and see when it prints forward while you move.
There is also an alternative method where you could get the player’s input from the player control module. Then you could just directly check the player input and see if its within a certain threshold.