Hey, I was playing SCP-3008 when I noticed this smooth camera movement. I looked everywhere and I didn’t think how to do it… Can you help me?
I really love SCP-3008, and I want to make a game the same way… With everything smooth…
and lol sorry my mic and monitor is bad bruh
2 Likes
Use LockFirstPerson
for this, then use a function to tilt the camera.
sorry if im asking you probably wont respond or say it but by any chance could you hand me the script?
Hey there!
I’ve seen the request that you’re asking for, and here’s my approach.
Attempt 1
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local ROTATION_SPEED = 0.05
local CAMERA_TILT_ANGLE = 15
local MAX_CAMERA_TILT_ANGLE = 30
local moveDirection = Vector3.new()
local lastMoveDirection = Vector3.new()
local cameraRotation = 0
local cameraTilt = 0
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter -- Lock the mouse to the center of the screen
function updateMovement()
local input = UserInputService:GetLastInputType()
if input == Enum.UserInputType.Keyboard or input == Enum.UserInputType.Gamepad then
local moveX = 0
local moveY = 0
if UserInputService:IsKeyDown(Enum.KeyCode.W) then
moveY = moveY + 1
end
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
moveY = moveY - 1
end
if UserInputService:IsKeyDown(Enum.KeyCode.A) then
moveX = moveX - 1
end
if UserInputService:IsKeyDown(Enum.KeyCode.D) then
moveX = moveX + 1
end
moveDirection = Vector3.new(moveX, 0, moveY)
else
moveDirection = Vector3.new()
end
end
function updateCamera()
local delta = RunService.RenderStepped:wait()
-- Update the camera rotation based on the mouse movement
local mouseDelta = UserInputService:GetMouseDelta()
cameraRotation = cameraRotation - mouseDelta.x * ROTATION_SPEED
-- Update the camera tilt based on the player's movement direction
if moveDirection.magnitude > 0.1 then
cameraTilt = math.clamp(cameraTilt + moveDirection.x * CAMERA_TILT_ANGLE * delta, -MAX_CAMERA_TILT_ANGLE, MAX_CAMERA_TILT_ANGLE)
else
cameraTilt = cameraTilt + (0 - cameraTilt) * delta * 2 -- Smoothly move the camera tilt back to zero when the player is not moving
end
-- Apply the camera rotation and tilt to the camera's CFrame
camera.CFrame = CFrame.new(player.Character.Head.Position) * CFrame.Angles(0, math.rad(cameraRotation), 0) * CFrame.Angles(math.rad(cameraTilt), 0, 0)
end
-- Connect the update functions to the appropriate events
UserInputService.InputChanged:connect(updateMovement)
RunService:BindToRenderStep("UpdateCamera", Enum.RenderPriority.Camera.Value, updateCamera)
This script checks for player input and updates the camera rotation and tilt based on the player’s movement direction. The updateMovement
function checks for keyboard or gamepad input and sets the moveDirection
vector accordingly. The updateCamera
function then updates the camera rotation and tilt based on the moveDirection
vector, and applies the resulting CFrame to the camera’s CFrame
property.
Thanks!
Very detailed And Explanatory!
One Tiny problem whenever i go in first person it lags the baseplate and the rest of the map
Hey there!
My apologies on the last reply. It could be a result of constantly calculating the CFrame
every frame, versus when an input is changed. Here’s the next attempt which should be “smoother”/less laggier.
Attempt 2
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local ROTATION_SPEED = 0.05
local CAMERA_TILT_ANGLE = 15
local MAX_CAMERA_TILT_ANGLE = 30
local moveDirection = Vector3.new()
local lastMoveDirection = Vector3.new()
local cameraRotation = 0
local cameraTilt = 0
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter -- Lock the mouse to the center of the screen
function updateMovement(input, gameProcessedEvent)
if gameProcessedEvent then -- Ignore inputs that have been processed by the game
return
end
local moveX = 0
local moveY = 0
if UserInputService:IsKeyDown(Enum.KeyCode.W) then
moveY = moveY + 1
end
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
moveY = moveY - 1
end
if UserInputService:IsKeyDown(Enum.KeyCode.A) then
moveX = moveX - 1
end
if UserInputService:IsKeyDown(Enum.KeyCode.D) then
moveX = moveX + 1
end
moveDirection = Vector3.new(moveX, 0, moveY)
end
function updateCamera()
if moveDirection ~= lastMoveDirection then
lastMoveDirection = moveDirection
-- Update the camera tilt based on the player's movement direction
if moveDirection.magnitude > 0.1 then
cameraTilt = math.clamp(cameraTilt + moveDirection.x * CAMERA_TILT_ANGLE, -MAX_CAMERA_TILT_ANGLE, MAX_CAMERA_TILT_ANGLE)
else
cameraTilt = cameraTilt + (0 - cameraTilt) * 0.1 -- Smoothly move the camera tilt back to zero when the player is not moving
end
end
-- Update the camera rotation based on the mouse movement
local mouseDelta = UserInputService:GetMouseDelta()
cameraRotation = cameraRotation - mouseDelta.x * ROTATION_SPEED
-- Apply the camera rotation and tilt to the camera's CFrame
camera.CFrame = CFrame.new(player.Character.Head.Position) * CFrame.Angles(0, math.rad(cameraRotation), 0) * CFrame.Angles(math.rad(cameraTilt), 0, 0)
end
-- Connect the update functions to the appropriate events
UserInputService.InputChanged:connect(updateMovement)
RunService:BindToRenderStep("UpdateCamera", Enum.RenderPriority.Camera.Value, updateCamera)
If any of my solutions help you out, feel free to mark my reply as the solution!
sorry if im asking oof
but how do you make it a solution?
Hey there!
That’s honestly a great question. I’ve started using the DevForums recently, so I’m not too sure.
You can’t as you’re not the OP, you can just like it.
I’ve just realized that as well, lol. Thanks for the reminder.
Hi! So uh, that’s a really old post, lol.
I was curious to test that script, so I tested…
Was that supposed to happen?
Change the value of Humanoid.CameraOffset
in order to bring the camera out more.