Camera shiftlock ruining flight system

I’m trying to achieve a clean flight system.

When I shiftlock and go down, it angles my player awkwardly.

When I don’t use shiftlock it acts normal as you can see in the video.

I’ve tried using input.Delta via UserInputService and if statements to check the mouse’s state but that hasn’t worked.

1 Like

Did you want to disable shift lock?

  1. Select StarterPlayer. In the Properties window, look for the property named EnableMouseLockOption.
  2. Set the EnableMouseLockOption property to false.

This will disable the ability for players to toggle Shift Lock.

1 Like

I want players to still use shiftlock.

1 Like

Could you send your code ? (character limit)

1 Like
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local Camera = workspace.CurrentCamera

local Character = script.Parent
local Root = Character:WaitForChild("HumanoidRootPart")

local FlyingFunctions = {}

--//Variables
local Flying
local Velocity = nil
function FlyingFunctions.Move(velocity)
	Velocity.VectorVelocity = velocity
end

function FlyingFunctions.Look()
	local mouseLocation = UserInputService:GetMouseLocation()
	local cameraRay = Camera:ViewportPointToRay(mouseLocation.X,mouseLocation.Y)
	if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
		Root.CFrame = CFrame.lookAt(Root.Position,Root.Position + cameraRay.Direction) * CFrame.Angles(math.rad(90),0,0)
	else
		Root.CFrame = CFrame.lookAt(Root.Position,Root.Position + cameraRay.Direction) * CFrame.Angles(math.rad(-90),0,0)
	end
	return cameraRay.Direction * 1e2
end


UserInputService.InputBegan:Connect(function(input,gpe)
	if gpe then return end
	if input.KeyCode == Enum.KeyCode.F then
		Velocity = Instance.new("LinearVelocity")
		Velocity.MaxForce = 1e6
		Velocity.Attachment0 = Root.RootAttachment
		Velocity.Parent = Character
		Flying = RunService.Heartbeat:Connect(function()
			local result = FlyingFunctions.Look()
			if result then FlyingFunctions.Move(result) end
		end)
	end
end)

UserInputService.InputEnded:Connect(function(input,gpe)
	if gpe then return end
	if input.KeyCode == Enum.KeyCode.F then
		Flying:Disconnect()
		Flying = nil
		Velocity:Destroy()
	end
end)