New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

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

Asked by
RubenKan 3570 Moderation Voter Administrator Community Moderator
3 years ago
Edited 3 years ago

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.

0
I would put the camera and mouse in one script. Maybe use the "while true do" loop. See if that helps. :) Admin8483 -21 — 3y

2 answers

Log in to vote
2
Answered by 3 years ago

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.

0
Thank you! This completely solves the problem. Now it's time for math ;-; RubenKan 3570 — 3y
Ad
Log in to vote
-2
Answered by
Admin8483 -21
3 years ago

Wait... just never move the mouse!

0
Wow he totally never thought of that... cough....cough....dumb. farrizbb 404 — 3y
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 RubenKan 3570 — 3y

Answer this question