Need help with creating this Camera effect from Doors

I wanna recreate this camera effect in the game Doors. Take a look:


You can see, if you quickly move the camera on the X axis, it slightly overshoots and gets back into position, and if you quickly move the camera on the Y axis, it tilts (or rolls) the camera based on fast the camera is rotating.

I’ve done countless DevForum searches, but to no luck. Any help is appreciated.
(Sorry if there’s anything missing that I need to show here! This is my first forum post. :P)

2 Likes

I really don’t know how to do it, but I was able to make a first person camera script so maybe you can start with that.

local RunService = game:GetService('RunService')
local UIS = game:GetService('UserInputService')

local Plr = game:GetService('Players').LocalPlayer
local MS = Plr:GetMouse()

local Camera = workspace.CurrentCamera

local currentAngle = Vector2.new(0,0)

RunService.RenderStepped:Connect(function()
	local Char = Plr.Character
	
	Plr.CameraMaxZoomDistance = 0

	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
	
	local Delta = UIS:GetMouseDelta()
	
	currentAngle -= (Delta / Camera.ViewportSize) * 10
	
	local maxY = math.rad(80)
	
	if currentAngle.Y > maxY then
		currentAngle = Vector2.new(currentAngle.X,maxY)
	elseif currentAngle.Y < -maxY then
		currentAngle = Vector2.new(currentAngle.X,-maxY)
	end
	
	if Char and Char:FindFirstChild('Head') then
		local Head:BasePart = Char.Head
		
		local Goal = CFrame.new(Head.Position) * CFrame.fromOrientation(currentAngle.Y,currentAngle.X,0)
		
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = Camera.CFrame:Lerp(Goal,.3)
	end
end)
1 Like

Are you able to explain your code? Thanks.

Ok, I’ll just add comments. (Just realized MS is not being used.)

local RunService = game:GetService('RunService')
local UIS = game:GetService('UserInputService')

local Plr = game:GetService('Players').LocalPlayer

local Camera = workspace.CurrentCamera

local currentAngle = Vector2.new(0,0) -- This is in radians btw

RunService.RenderStepped:Connect(function() -- Running this function every frame/renderstepped
	local Char = Plr.Character
	
	Plr.CameraMaxZoomDistance = 0

	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter -- UIS:GetMouseDelta() only works if the mouse is locked.
	
	local Delta = UIS:GetMouseDelta()
	
	currentAngle -= (Delta / Camera.ViewportSize) * 10
	-- Dividing the delta by the viewport size of their camera gives a Vector2 from 0 to 1, then multiplying it by 10 will increase it from 0 to 10, then we subtract the currentAngle by the new Vector2 we have gotten.
	
	local maxY = math.rad(80)
	
	if currentAngle.Y > maxY then -- If it's greater than maxY, set it to maxY
		currentAngle = Vector2.new(currentAngle.X,maxY)
	elseif currentAngle.Y < -maxY then -- if it's less than -maxY, set it to -maxY (-maxY is basically just negative maxY)
		currentAngle = Vector2.new(currentAngle.X,-maxY)
	end
	
	if Char and Char:FindFirstChild('Head') then -- Checking if Character exists and it has a head
		local Head:BasePart = Char.Head
		
		local Goal = CFrame.new(Head.Position) * CFrame.fromOrientation(currentAngle.Y,currentAngle.X,0)

		-- We multiply a new CFrame that is at the head position by an orientation that uses currentAngle, the camera basically rotates like this;

		-- X Axis = Up, Down
		-- Y Axis = Left, Right
		-- Z Axis = Roll Left, Roll Right
		
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = Camera.CFrame:Lerp(Goal,.3) -- Then we lerp the camera's CFrame to the new goal by 0.3
	end
end)

-- Sorry if I didn't really explain this well, I've never explained code before

Uhh… I still don’t quite understand. Can you tell me what your code is doing?

Ok, It basically just set’s the Camera.CFrame to the Head.Position multiplied by the currentAngle.

Multiplying a CFrame.new(Vector3) by a CFrame.fromOrientation(x,y,z) (or just any angle), is basically just adding them together.

Hm, I do see a little bit of tilting, but I need to move my camera at ridiculous speeds. Is there a way to make the tilting more obvious?

On this part, change the Z axis to be the delta of your mouse (X or Y, idk). Then you probably need to multiply it so it’s more obvious.

I still don’t get it. I changed 0 to currentAngle.Y, but everytime I look down/up, it tilts the camera based on how high/low my view is.

I’m really sorry if there’s something obvious that I didn’t know about! I’m not very familiar with CFraming. :frowning:

Sorry for replying 1h later, but no, not currentAngle.Y, I meant Delta.Y

Alright! Seems to work like a charm. Appreciate your help, really.
Although, there’s stuttering that’s kinda noticeable, if you see the video:


But, if there’s no solution, then I could use a little bit of camera shake to hide the stuttering. Again, thank you. [EDIT: Nope, even with camera shake, it still looks pretty noticeable. :P]

2 Likes

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