I was thinking about this when reading the part under Notes
I’m playing around with Scriptable right now, and I was sort of hoping that I would be able to have access to an accurate Delta instead of Vector3.new(0, 0, 0), seeing as you would think that the mouse would be independent of the camera. Could we get this behavior when the camera’s CameraType is set to Scriptable? It seems to be working as expected for all other CameraTypes.
Reproduce with the following code in a LocalScript and look at output to get a feel for what I’m trying to say
game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
game:GetService("UserInputService").InputChanged:connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
print("delta is (" .. tostring(inputObject.Delta.x) .. ", " .. tostring(inputObject.Delta.y) .. ")")
end
end)
workspace.CurrentCamera.Changed:connect(function(property)
if property == "CameraType" then
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
end
end)
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
For MouseLocked to actually lock the mouse instead of letting it jitter around on the screen when you see the mouse cursor move for a split second before it gets moved back
Was actually thinking of you and thinking back to Alianor III when I was making this post! Still need this support and control over mouse sensitivity to have first person shooters be not as hacky.
When I run your code in Test Server + Player I don’t see the mouse being locked. The mouse is locked and the delta works if I modify your code like this:
game:GetService("UserInputService").InputChanged:connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
print("delta is (" .. tostring(inputObject.Delta.x) .. ", " .. tostring(inputObject.Delta.y) .. ")")
end
end)
workspace.CurrentCamera.Changed:connect(function(property)
if property == "CameraType" then
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
end
end)
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
-- Wait for next frame and then lock the mouse
game["Run Service"].RenderStepped:wait()
game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
I’ve used mouse lock + delta + scriptable in many projects for months, it works fine. I’m not sure why the wait makes it work, I don’t use this in my own projects. It may be that you need to wait a while before you can set any of the mouse’s options.
[quote] When I run your code in Test Server + Player I don’t see the mouse being locked. The mouse is locked and the delta works if I modify your code like this:
game:GetService("UserInputService").InputChanged:connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
print("delta is (" .. tostring(inputObject.Delta.x) .. ", " .. tostring(inputObject.Delta.y) .. ")")
end
end)
workspace.CurrentCamera.Changed:connect(function(property)
if property == "CameraType" then
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
end
end)
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
-- Wait for next frame and then lock the mouse
game["Run Service"].RenderStepped:wait()
game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
I’ve used mouse lock + delta + scriptable in many projects for months, it works fine. I’m not sure why the wait makes it work, I don’t use this in my own projects. It may be that you just can’t lock the mouse right after changing the camera type or something. [/quote]
Wow, that’s really weird. We shouldn’t have to do that…
I was sort of hoping for Delta even when LockCenter is off as well.
Here is some code for you that will get the right delta in both situations. So this will even show a delta when the camera is Scriptable and the mouse is unlocked.
local UIS = game:GetService("UserInputService")
local mouse = game.Players.LocalPlayer:GetMouse()
local lastx, lasty = mouse.X, mouse.Y
UIS.InputChanged:connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
-- Take delta from inputObject as default:
local delta = inputObject.Delta
if UIS.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
-- If locked, we calculate delta ourselves:
delta = Vector2.new(mouse.X - lastx, mouse.Y - lasty)
end
lastx, lasty = mouse.X, mouse.Y
-- Now we get the right delta, no matter if mouse was locked or unlocked:
print("delta is (" .. tostring(delta) .. ")")
end
end)
workspace.CurrentCamera.Changed:connect(function(property)
if property == "CameraType" then
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
end
end)
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable