Hello guys, today I’m having a bit of an issue concerning mouse lock. I have a script set up so that with the press of a key, you can toggle between roblox’s default first person mode, and a custom third person mode. The issue is that even with me making it so that it locks the mouse, it still forces the mouse to be unlocked, which practically disabled my third person view system. (Atleast I believe that’s the issue)
Here’s the block of code that’s relevant to my problem:
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.V then
if firstPerson == false then
firstPerson = true
Camera.CameraType = Enum.CameraType.Custom
localPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
else
firstPerson = false
Camera.CameraType = Enum.CameraType.Scriptable
localPlayer.CameraMode = Enum.CameraMode.Classic
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end
end
end)
You can see here that if you press the ‘V’ key, it uses roblox’s default first person mode, and if you press it again, it lets my custom third persion view take control over the camera.
You can see here in the gif what I’m experiencing.
Make it so, after you zoom out, lock the mouse, because while you zoom out the MouseBehaviour turns to default since it’s Classic camera mode. Try that.
No, I did not. It switches the camera mode upon key press.
There’s no code that zooms it out apart from switching from first person to classic, and setting the minimal zoom so you can’t zoom into first person. In fact, you can’t zoom at all because of how my camera system works.
That’s what I wanted. At the line of code you set the camera’s zooming boundries (zooming out), you have to add the MouseBehaviour.LockCenter line, right below that, maybe add a wait() incase it is still zooming out after trying to lock it (or wait for the tween to finish etc etc, always depending how’s scripted).
I think you misundestand. The minimal zoom is set in the initialization of the script and is never changed. The only zooming out is done automatically by roblox’s default camera system when changing the CameraMode’s. My problem is that the mouse unlocks, and I’ve tried to fix that by setting the LockCenter in the initialization and during the change.
You set the CameraMode to Classic and at the same time, you also set the MouseBehavior to LockCenter. But because of how the default CameraModule works, it sets the MouseBehavior to Default at the NEXT FRAME after you “free” the camera
summary
-- First person
FirstPerson -> set CameraType to Custom -> set MouseBehavior to LockFirstPerson
-- Third person
ThirdPerson -> set CameraType to Classic -> set MouseBehavior to LockCenter
-- next frame
Roblox CameraModule found out CameraType is classic -> check minimum zoom ->
-> zoom is less than minimum so set zoom to minimum -> zoom is more than 0.5 so set MouseBehavior to Default
-- this part is where you need to add the RunService.Heartbeat:Wait()
-- after Heartbeat:Wait()
set MouseBehavior to LockCenter