Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to rotate the camera in a 2D game?

Asked by 3 years ago

I'm working on a 2D game right now, and what I'm trying to figure out is how to get the camera to rotate around the player.

Here's what I've got. This is a local script located in StarterPlayer.StarterPlayerScripts. CamX, CamY and CamZ are all NumberValues.

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

local val = game.Workspace.Values
local CamX = val.CamX.Value
local CamY = val.CamY.Value
local CamZ = val.CamZ.Value

player.CharacterAdded:Wait()

player.Character:WaitForChild("HumanoidRootPart")

camera.CameraSubject = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Attach
camera.FieldOfView = 40

local RunService = game:GetService("RunService")

local function onUpdate()
    if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
        camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(CamX,CamY,CamZ)
    end
end

RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onUpdate)

If you need me to clarify something, I'll be glad to do so! :)

0
what is your problem in your script? Xapelize 2658 — 3y

Answer this question