Mouse Delta Always 0,0,0

I am trying to make a custom camera system, similar to an over the shoulder camera but with the ability to still zoom in and out, but when I try to capture the mouse movement when the mouse behavior is set to lock center, it does not work and always returns 0,0,0. (See sample code below)
I notice that it picks up the mouse delta correctly if I hold the right mouse button and turn the camera in the default camera type, but it does not work moving it around normally.
I’ve tried searching for an answer and found this dev forum post and this camera manipulation article, but both did not help.

My Code
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera

UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter


local function mouseMovement (actionName, inputState, inputObject)
	print(inputObject.Delta) -- 0, 0, 0
end
ContextActionService:BindAction("MouseMovement",mouseMovement, false,Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)

game:GetService("RunService").RenderStepped:Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable
end)

Delta is only calculated when the mouse is locked in place, when UserInputService.MouseBehaviour is set to either “LockCenter” (done automatically when fully zoomed in, aka in “first-person”) or “LockCurrentPosition”.

You can just do something like local Delta = MousePosition - LastMousePosition if you don’t want to lock the player’s mouse.

3 Likes

That is what I did, but looking back at my code I think that I need to set this property after I set the camera type to scriptable because it may be resting. Just got off studio, though, so I’ll need to test that later.

Edit: This was the case, and so this solution is not the exact same as the other forum post I mentioned, I should mention that you need to set the property UserInputService.MouseBehavior after you set the CameraType to Scriptable.

2 Likes