I’m making a new 2D platformer game, and I need help making a script
What I want is for the camera to always be facing the same direction, but I still want it to move with the player.
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
-- Set the initial camera position and orientation
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(character:WaitForChild("Head").Position + Vector3.new(30, 10, 0), character.Head.Position)
-- Update camera position to follow the player
game:GetService("RunService").RenderStepped:Connect(function()
if character and character:FindFirstChild("Head") then
-- Adjust the camera's position based on the player's position
local targetPosition = character.Head.Position + Vector3.new(30, 10, 0) -- Adjust the offset values as needed
camera.CFrame = CFrame.new(targetPosition, character.Head.Position)
end
end)
As you can see:
Place script as a local script inside PlayerStarterScripts or you can adjust it as a CharacterStarterScript