How to disable mouse's locking action when right clicking?

Hello!

Whenever you right click and move your mouse, it locks at it’s current position, and you can freely rotate the camera around the player’s character. I was wondering how I can disable this feature - I guess in the CameraModule script inside the PlayerModule script?

6 Likes

Yes, you need to disable the part of CameraModule that does that. You can also implement your own solution if you need this feature but in different circumstances with this.

3 Likes

I tried commenting this part of the “BaseCamera” ModuleScript which is a child of the “CameraModule” ModuleScript: (line 510-511)

   -- elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
    --		self:OnMouse2Down(input, processed)

This removed the feature of rotating the camera around the player, but the cursor is still locked at it’s last position. I’ve tried searching through these ModuleScripts and I can’t find any fix to this.

You have a few options here. There are a few CameraTypes that might support the functionality you are looking for. If not you can create a scriptable camera that follows the player’s root part.

If you decide to override the CameraModule you are going to need to find the connection in which it sets the behavior type of the mouse to LockCurrentPosition. Just search the script and you should find it. Also, make sure that this doesn’t interrupt any connections within the RunService portion of the code.

1 Like

You could just avoid forking the CameraModule altogether and sink the input of the right mouse button instead. I prefer doing this over forking entire modules for a few small tweaks that can be achieved in other ways. I usually reserve forking for major edits or if alternatives aren’t reasonably available.

local ContextActionService = game:GetService("ContextActionService")

ContextActionService:BindActionAtPriority("RightMouseDisable", function()
	return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.Medium.Value, Enum.UserInputType.MouseButton2)

CameraModule implements the right mouse behaviour via UserInputService.InputBegan. What we can do is take advantage of ContextActionService’s BindActionAtPriority method to bind a function to an input type with a high priority that’ll run over InputBegan. Said function simply sinks the input if called.

Throw this in a blank LocalScript in StarterPlayerScripts and give it a try - you won’t be able to use your right mouse button to turn your camera.

14 Likes

Thanks! That’s a lot easier too!

Although the problem now is that my own LocalScripts won’t register right mouse button inputs. Is there any way to prevent this?

Ah, right. Given that ContextActionService is acting on the right mouse button, that means that most right mouse button interactions would be invalidated since it runs over UserInputService.

You may have to switch any right mouse input over to ContextActionService or look back into the CameraModule to attempt to remove the right mouse code. I could try doing the latter if I have time.

What you could do is switch the ContextActionPriority of the RightMouseDisable action to low, then use BindActionAtPriority again to bind your other right mouse actions but with a higher priority. For example, RightMouseDisable can have Enum.ContextActionPriority.Low.Value, while another one of your actions uses Enum.ContextActionPriority.Low.Value + 100.

1 Like

Nice this worked for me, also if you want to reenable the rightmouse camera movement just replace the line
“return Enum.ContextActionResult.Sink”
with
“return Enum.ContextActionResult.Pass”

Please Roblox, let us disable this thing in the game Esc manu :pray:

you can make that a post in feature requests!