Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i force move a mouse?

^ title ^

i need help with that to add recoil to my guns.

1 comment

0

It is impossible to move the players mouse using a script, this would be a big security risk. You can however change the players camera.

1 answer

✓ Accepted answer

You can rotate the camera upwards by pre-multiplying the camera's CFrame with a rotation matrix:

cam = workspace.CurrentCamera

-- rotate 5 degrees upwards
cam.CFrame = cam.CFrame * CFrame.Angles(math.rad(5), 0, 0)

You can connect this bit of code in a function to mouse clicking, shooting your gun, or something even more interesting like bumps in a car ride, earthquakes, or flinching when the player gets shot. Just change the number 5 to move up and down by different values, or put numbers in the other 0 fields to rotate in different directions.

cam = workspace.CurrentCamera

function Recoil(degrees)
	-- rotate 'degrees' upwards
	cam.CFrame = cam.CFrame * CFrame.Angles(math.rad(degrees), 0, 0)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.