Limit how fast the player can rotate the camera in first person

Hello, I was finishing some things for the player camera in a ROBLOX horror game I was making, and so far everything was good, except one thing; you can spin the camera without a limit, which isn’t a cool detail.

So I noticed a roblox game called “DOORS” prevented that when ingame, by having a rotation limit being applied when spinning too fast. I also noticed tiny details into it such as this specific one:

If the camera spins very fast immediately, the rotation will be fast but at a slow rate, instead if you gradually go up until you’re spinning very fast again, the rotation rate will be faster than the instant one.

This is one time where I can’t figure something like that out because either i’m bad at researching or I haven’t scripted with camera enough to know this. Also no i’m not talking about the camera sway effect, but the speed rate limit, this is an example footage if anyone can help me out:

2 Likes

Hi!
Setup a heatbeat or renderstepped connection.

local oldCameraAngle = camera.CFrame.Orientation
-- connection
camera.CFrame.Orientation = CFrame.new(camera.CFrame.Position) + CFrame.Angles(
math.clamp(camera.CFrame.Orientation.X,oldCameraAngle.X - 10,oldCameraAngle.X + 10)
,
math.clamp(camera.CFrame.Orientation.Y,oldCameraAngle.Y - 10,oldCameraAngle.Y + 10)
,
math.clamp(camera.CFrame.Orientation.Z,oldCameraAngle.Z - 10,oldCameraAngle.Z + 10)
)
oldCameraAngle = camera.CFrame.Orientation

This is not working at the current state, but the idea is, that you each frame update their camera orientation, and does so the angle can maximum be -10 or +10 in each direction of oldCameraAngle.

Math.clamp can be used to keep a number between a min & max value. Ect:

math.clamp(3333,-10,400) -- Returns 400
math.clamp(-3333,-10,400) -- Returns -10
math.clamp(333,-10,400) -- Returns 333

Tried a bit of variation with that but I still can’t get it to work properly.

Note: the custom camera I made constantly follows the head position and it’s a “scriptable” camera

Could you help me a bit more on this? I get the intention on what to do but I can’t properly put it in use

See if this is what you’re looking for.

local userInputService = game:GetService("UserInputService")
local UserGameSettings = UserSettings():GetService("UserGameSettings")

local maxSentivity = 0.1

local mouseDeltaSensitivity = maxSentivity / UserGameSettings.MouseSensitivity 
userInputService.MouseDeltaSensitivity = mouseDeltaSensitivity

UserGameSettings:GetPropertyChangedSignal("MouseSensitivity"):Connect(function()
	mouseDeltaSensitivity = maxSentivity / UserGameSettings.MouseSensitivity 
	userInputService.MouseDeltaSensitivity = mouseDeltaSensitivity
end)

Taken from this thread.

Nope i’m not looking for a sensitivity limit, i’m looking for a rotation speed limit like you see in the video, where my sensitivity is the same, but if i go ahead of a certain speed it doesnt go that fast

Well,
I’m still uncertain what effect you’re trying to achieve, since the script above limits how fast you can rotate the camera in first person. Hopefully you’ll figure it out.


This is a regular camera if spinned very fast (game: Natural Disaster Survival)


This is DOORS camera if spinned very fast, you can see its still fast but there’s some sort of limit to prevent supersonic spinning

try using a function bound to context action service

(this is a local script)

local ps = game:GetService('Players')
local pl = ps.LocalPlayer
local cas = game:GetService('ContextActionService')

pl.CharacterAdded:Connect(function(ch)
	
	local hum = ch:WaitForChild("Humanoid")
	local root = ch:WaitForChild("HumanoidRootPart")

	local limit = 60
	local camangx, camangy = 0, 0
	
	local function playerInput(actionName, inputState, inputObject)
		if inputState == Enum.UserInputState.Change then
			camangx = math.clamp(camangx - inputObject.Delta.X, camangx - limit, camangx + limit)
			camangy = math.clamp(camangy -inputObject.Delta.Y, camangy - limit, camangy + limit)
		end
	end
	cas:BindAction("playerInput", playerInput, false, Enum.UserInputType.MouseMovement)

end)

(note this function does not update the camera and only tells the camera the value the mouse has been moved (clamped by the limit)