Camera affecting Player's movement in a Lock System

Actually, instead of all that complicated code, you could just use the raw input direction directly from the player module:

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

Source: How would I go about detecting the direction a player is inputting for their character across platforms? - #5 by dogwarrior24

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

-- Note the priority needs to be after the `.Character` priority.
RunService:BindToRenderStep("MoveOverride", Enum.RenderPriority.Character.Value + 1, function()
	if player.Character then
		local humanoid = player.Character:FindFirstChild("Humanoid")
		local hrp = player.Character:FindFirstChild("HumanoidRootPart")
		if humanoid and hrp then
			local characterCFrame = hrp.CFrame

			local fixedDirection = Vector3.zero
			-- Get the raw input direction from the player module
			local inputDirection = getInputDirection()
			if inputDirection ~= Vector3.zero then
				-- Convert the input direction into world space
				fixedDirection = characterCFrame:VectorToWorldSpace(inputDirection)
			end

			humanoid:Move(fixedDirection, false)
		end
	end
end)

That’s much more likely to work properly.

1 Like