Like the title already says, I’m currently trying to restrict the players movement to a certain axis (in my case I only want the player to move sideways)
I’ve already come across a few solutions but they either don’t work on all devices or are rather complicated (such as using BodyGyros/BodyVelocities and then manually moving the player when the A/D key was pressed)
Does anyone know a good solution for this problem?
(PS: Unbinding the W/S button isn’t really an option because movement depends on the cameras angle.
I would manually reposition the player every physics step:
-- in StarterCharacterScripts
local character = script.Parent
local zPosition = 0 -- will force the player to Z = 0
game:GetService("RunService").Heartbeat:Connect(function()
local root = character:FindFirstChild("HumanoidRootPart")
if root then
root.CFrame = root.CFrame + Vector3.new(0, 0, zPosition - root.Position.Z)
end
end)
This avoids any physics weirdness with using a constraint, but still allows for the normal roblox control scripts to run.