How to create a MouseLock style camera?

Alrighty, so basically, I’m trying to create a MouseLock style camera for a gun kit that I’m creating. I tried to do Enum.CameraMode.LockFirstPerson then set the min and max CameraZoomDistance to 25 in hopes that it would lock the cursor in place while still allowing me to move the Camera but that method didn’t work.

Example of what I mean:
https://gyazo.com/552b1b367007f2b04fa711ef3fedcbe9
As I aim the gun the cursor is locked in place while the camera moves to allow you to aim.

2 Likes

Maybe this will work:

local UserInputService = game:GetService("UserInputService")
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

I made a system similar to this two years ago so my information might not be the best.
You will have to lock the mouse as C0lvy123 stated then create a custom camera script.
In the camera script you’ll have to get the input of the mouse to move the camera around.
Then you can use Humanoid.AutoRotate to move the character with the camera.

These links should be helpful:
https://developer.roblox.com/en-us/api-reference/function/UserInputService/GetMouseDelta

https://developer.roblox.com/en-us/api-reference/property/Humanoid/AutoRotate

2 Likes

I tried this and It didn’t quite work the way I wanted it to. It locks the mouse in place but it doesn’t allow the camera to move.

1 Like

Thank you for linking these! This was a big help :]

1 Like