I want to make it so you are able to rotate your camera by holding right mouse button like when the camera type is set to “Orbital” but I do not know how to do that.
(The script is a local script in starter character scripts) Here is the code:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local cameraDepth = 74
local heightOffset = 2
local fov = 20
camera.FieldOfView = fov
local function updateCamera()
local rootPosition = humanoidRootPart.Position + Vector3.new(0, heightOffset, 0)
local cameraPosition = rootPosition + Vector3.new(cameraDepth, cameraDepth, cameraDepth)
camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)
end
game:GetService("RunService"):BindToRenderStep("TopDownCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)
Use UserInputService to get the mouse delta. Times this by the deltaTime to get how much you should rotate the camera. Store this current rotation in its own variable. It should look something like this:
local userInputS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local cameraDepth = 74
local heightOffset = 2
local fov = 20
camera.FieldOfView = fov
local currentAngle = 0
local sensitivity = 1 -- decrease this to go slower
local function updateCamera(deltaTime)
local mouseDeltaX = userInputS:GetMouseDelta().X
currentAngle += mouseDeltaX * deltaTime * sensitivity
local rootPosition = humanoidRootPart.Position + Vector3.new(0, heightOffset, 0)
local cameraCF = CFrame.new(rootPosition) * CFrame.Angles(0, currentAngle, 0) * CFrame.new( Vector3.new(cameraDepth, cameraDepth, cameraDepth))
camera.CFrame = CFrame.lookAt(cameraCF.Position, rootPosition)
end
game:GetService("RunService"):BindToRenderStep("TopDownCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)
Do keep in mind I haven’t tested this, so some obvious mistakes might need fixing.