How would I start on a sensitivity script?

Hello DevForum,
I’m making a paintball game by myself currently, and I’m trying to figure out how I would make a mouse sensitivity script. I’ve been trying to think about how to start for a couple of hours, but I have no idea how to start. Heres my attempt :

rs.RenderStepped:connect(function()
   cam.CFrame = cam.CFrame:Lerp(CFrame.new(cam.CFrame.p, mouse.hit.p), Sensitivity*0.01)
end)

As you can see, it’s not a very good script. All it does is make the camera turn. I’m trying to make a sensitivity script like in one of my favorite Roblox games of all time, Nerf FPS.

I have a feeling MouseDeltaSensitivity would work, but I’ve tried, I couldn’t figure that out.

@IsaacThePooper

3 Likes

I would suggest using the GetMouseDelta() from the UserInputService or any way of getting how much the mouse moves. You can then set the camera’s cframe like so:

local Delta = UserInputService:GetMouseDelta()
rs.RenderStepped:Connect(function()
    cam.CFrame = cam.CFrame * CFrame.Angles(0, math.rad(0, (Delta.X * 0.01) * (Sensitivity * 0.01)
end)

This came from the top of my head so sorry if anything is wrong about it.

1 Like
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom

local Sensitivity = 3
local UserInputService = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local cam = workspace.CurrentCamera

local Delta = UserInputService:GetMouseDelta()
rs.RenderStepped:Connect(function()
	local DeltaX = math.rad((Delta.X * 0.01)*(Sensitivity*0.01))
	local DeltaY = math.rad((Delta.Y * 0.01)*(Sensitivity*0.01))
	
	print(DeltaX)
    cam.CFrame = cam.CFrame * CFrame.Angles(0, DeltaX, 0)
end)

It didn’t work. It always printed 0 in the output.

1 Like

Oops sorry forgot to mention UserInputService.MouseBehavior has to be set to Enum.MouseBehavior. LockCenter. With this method, you can actually incorporate MouseDeltaSensitivity into this now.

1 Like

Make sure the camera is scriptable and you have mouse locked to center. (these are a must).

Then get the delta of the mouse every frame and multiply that by the sensitivity. (I usually multiply delta by 0.2 to start anyway).

(Here’s what I do)

Add the delta to a rotx and roty variable and then use than in the angular rotation of the camera.

Then offset the camera based on a object such as HumanoidRootPart then use a CFrame Offset for the Head such as 0,2,0 then multiply by rotX then rotY.

This is sample code:

local rotX, rotY = 0,0
local min,max = math.rad(-80),math.rad(80)
game:GetService("RunService").RenderStepped:Connect(function()
    --get Delta using GetMouseDelta, I use an outdated method in getting it...
    rotX = rotX - math.rad(deltaX)
    rotY = math.min(math.max(rotY - math.rad(deltaY), min), max)
    camera.CFrame = 
	CFrame.new(rootPart.Position) *
	CFrame.new(0, 4, 0) *
	CFrame.Angles(0, rotX, 0) *
	CFrame.Angles(rotY, 0, 0)
end)
2 Likes

Thank you dude! Now I can continue my paintball game!
:+1:

1 Like