How to rotate the camera in a 2D game?
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.
01 | local player = game.Players.LocalPlayer |
02 | local camera = workspace.CurrentCamera |
04 | local val = game.Workspace.Values |
05 | local CamX = val.CamX.Value |
06 | local CamY = val.CamY.Value |
07 | local CamZ = val.CamZ.Value |
09 | player.CharacterAdded:Wait() |
11 | player.Character:WaitForChild( "HumanoidRootPart" ) |
13 | camera.CameraSubject = player.Character.HumanoidRootPart |
14 | camera.CameraType = Enum.CameraType.Attach |
15 | camera.FieldOfView = 40 |
17 | local RunService = game:GetService( "RunService" ) |
19 | local function onUpdate() |
20 | if player.Character and player.Character:FindFirstChild( "HumanoidRootPart" ) then |
21 | camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(CamX,CamY,CamZ) |
25 | RunService:BindToRenderStep( "Camera" , Enum.RenderPriority.Camera.Value, onUpdate) |
If you need me to clarify something, I'll be glad to do so! :)