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)
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)
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
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]