So I’m making a 2D platformer game. But I’ve got something that I can’t solve.
I want the camera to be locked on the X and Y axis, but I don’t know how to do. There’s nothing wrong with the script. I don’t want the player to be able to move the camera at all.
Here’s the script:
local RunService = game:GetService("RunService")
local Camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
Camera.CameraType = Enum.CameraType.Attach
Camera.CameraSubject = player.Character:WaitForChild("HumanoidRootPart", 0.5)
RunService.Stepped:Connect(function()
Camera.CFrame = CFrame.new(player.Character:WaitForChild("HumanoidRootPart", 0.5).Position) + CFrame.new(0,0,10)
end)
local RunService = game:GetService("RunService")
local Camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local HRP = character:WaitForChild("HumanoidRootPart")
Camera.CameraType = Enum.CameraType.Attach
Camera.CameraSubject = player.Character:WaitForChild("HumanoidRootPart", 0.5)
RunService.Stepped:Connect(function()
Camera.CFrame = CFrame.new(Camera.CFrame.X, Camera.CFrame.Y, HRP.CFrame.Z + 10)
end)
I don’t think you can “lock” the camera but you can control the camera through script. This tutorial includes a good section on how to do so How To Make Your Own 2D Game (NEW ASSET ADDED)