Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i lock my mouse in the center, but have my camera type on scriptable?

My problem is that i have to use Camera:SetRoll(Angle), which is only available to cameras with their CameraType set to Scriptable.

However, UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter doesn't work when the camera is on Scriptable.

Is there any other way to lock the mouse in the center, while being able to read out MouseDelta? I can't make the character fly around in first person, because that also doesn't allow me to use MouseBehavior.

TL;DR; I need a way to lock the mouse in the center of the screen while the CurrentCamera type is Scriptable, and still being able to read out InputObject.MouseDelta.

1 comment

0

I would put the camera and mouse in one script. Maybe use the "while true do" loop. See if that helps. :)

2 answers

✓ Accepted answer

If you name a local script 'CameraScript' and place it inside StarterPlayerScripts, it will replace the default CameraScript with your script.

When using a normal local script inside somewhere that isn't StarterPlayerScripts this won't work, but if you use this method you can.

For example I can name my local script 'CameraScript' and place it in StarterPlayerScripts. I can then add this:

local userInputService = game:GetService('UserInputService')

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()

wait() -- You can remove this, but I do this just in case.

camera.CameraType = Enum.CameraType.Scriptable

userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

userInputService.InputChanged:connect(function(inputObject) -- You can still read mouse delta.
	if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
		print('Delta X:' .. tostring(inputObject.Delta.x))
		print('Delta Y:' .. tostring(inputObject.Delta.x))
	end
end)

You can read more about this on the wiki page here.

1 comment

0

Thank you! This completely solves the problem. Now it's time for math ;-;

Wait... just never move the mouse!

2 comments

0

Wow he totally never thought of that... cough....cough....dumb.

0

Well guess what? The game resolves around moving your mouse to rotate the map around.. Suggest to remove this answer before you get too many downvotes ;p

This discussion is preserved as it was. New answers, comments, and votes are closed.