Get mouse movement while the mouse is locked

I have a basic physic grab system, however the one more thing I want to add is the ability to rotate object while holding it. (Think garry’s mod phys gun)
However I have problem with rotating the object, because I want to use mouse movement while the mouse sensitivity is set to 0, so getting mouse delta doesn’t work with this, using input position seem to just also give me one value only, weirdly. I’ve tried searching the forums but most are solved with getting mouse delta, which doesn’t work with what I’m doing.
Here’s me using mouse delta and setting the mouse sensitivity to really low value and multiplying the movement delta


The problem with this approach is that for the first frame the rotation will jump before moving at the sped I want.
And also this just seem very hacky so I’m trying to look for a better approach.

I’ve already tried using user input service but keep getting only one value from the position
image

1 Like

Hi,

  1. Hit play and spawn in your character.

  2. Under your PlayerScripts, you’ll find PlayerScriptsLoader and PlayerModule which roblox naturally injects in. This system controls your movement and camera on all platforms.
    image

  3. Copy it and paste it into StarterPlayerScripts. You now override roblox’s script injection with your own version of their script as long as the same name is used.

  4. You can now modify their camera control system.

  5. In BaseCamera, there is a function detailing camera rotation detection, “CalculateNewLookCFrameFromArg”, use this to figure out which module(s) are controlling the camera.
    image

  6. In this case I found the relevant module in ClassicCamera, but you will find it in other camera modes if you plan to use a different mode (such as VR or Orbital).

  7. Scrolling a bit towards the top you’ll find a section where the code is getting the mouse input to feed to the camera rotation:

  1. Replace it with:
-- assumption: game.UserInputService.MouseDeltaSensitivity = 1
local rotateInput = CameraInput.getRotation()
print(rotateInput)
rotateInput = Vector2.new(0,0) -- set rotateInput to 0,0 to lock the camera rotation
-- you can still read the original rotateInput to get the rotational value

You now can “lock” the camera in place without setting the mouse sensitivity to 0 while also receiving rotational input from the user.

4 Likes

I did not expect such a detailed reply, you rocks!

3 Likes

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.