I have an old script that I found that enables mouse lock on mobile the button is pressed. It works, but players that have it enabled look like they are having a seizure. I looked up Camera.CoordinateFrame and saw that it is deprecated and that Camera.CFrame should be used instead. How would I use CFrame to get the same effect that this has?
lockButton.Visible = userInputService.TouchEnabled
lockButton.MouseButton1Click:Connect(function()
if not locked then
local character = player.Character
local humanoidRootPart = character.HumanoidRootPart
locked = true
while locked do
local p = workspace.CurrentCamera.CoordinateFrame.lookVector * 999
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, Vector3.new(p.X, humanoidRootPart.Position.Y, p.Z))
runService.RenderStepped:Wait()
end
else
locked = false
end
end)
lockButton.Visible = userInputService.TouchEnabled
lockButton.MouseButton1Click:Connect(function()
if not locked then
local character = player.Character
local humanoidRootPart = character.HumanoidRootPart
locked = true
runService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Camera.Value + 1, function()
if not locked then
return
end
local camera = workspace.CurrentCamera
local offset = CFrame.new(1.75, 0, 0)
userGameSettings.RotationType = Enum.RotationType.CameraRelative
if camera then
if (camera.Focus.Position - camera.CFrame.Position).Magnitude >= 0.99 then
camera.CFrame = camera.CFrame * offset
camera.Focus = CFrame.fromMatrix(camera.Focus.Position, camera.CFrame.RightVector, camera.CFrame.UpVector) * offset
end
end
end)
else
locked = false
end
end)
This usually happens because as the player is moving, roblox doesn’t exclude the joystick on mobile devices, so roblox thinks your aiming at the joystick, when your actually moving, one way to fix this problem is to make a Mobile-Shiftlock system, where it forces the mouse to be in the middle.
one example of this happening is from the endorsed models that roblox released ages ago: [Endorsed Model]