Problem with camera

Hello Developers!

I have a problem where I want my camera to be in a 2d way but it keeps doing this. Watch the video!

robloxapp-20210718-2142239.wmv (2.1 MB)

Sorry for making you download it but I don’t know how to make it show the video!
If you know how to please show me!

1 Like

Are you using one of the preset camera modes?

1 Like

I just put the camera in a script

local player = game.Players.LocalPlayer
local camera = game.Workspace.Camera

player.CharacterAdded:Wait()
player.Character:WaitForChild("HumanoidRootPart")

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

game:GetService("RunService").Stepped:Connect(function()
	camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,30)
end)

You’re going to want to set the CameraType to “Scriptable”.

You need to determine which direction your levels are being built on. If the player constantly moves towards a higher X position, then you can base your camera’s position off of that. I’ll try to get an example put together for you.

Thanks for the help! I appreciate it!

Do you know how to upload a video?

Yes, I’ll lay it all out for you to understand in a moment.

I’ll get the video up and explain the logic. If it works out, you can mark that as a solution.

Are you there? Did ya get the video?

For this solution, I’m using an invisible, anchored part to position the camera.

You can create a simple part and anchor it in the world. Name the newly created part to anything that is easy to reference. For example, “CameraView”. Set the part’s Transparency to 1, making it invisible.

Next, we want to position the Camera on the part, but also lock it’s position with the player’s Y position. In code, we’ll set the part’s position before setting the camera’s position.

local Player = game.Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();
local Camera = workspace.CurrentCamera;

repeat -- This was a weird hack, but you just need to set the CameraType to Scriptable.
wait();
Camera.CameraType = Enum.CameraType.Scriptable;
until Camera.CameraType == Enum.CameraType.Scriptable;

game["Run Service"].Stepped:Connect(function(t, deltatime)
    workspace.CameraView.CFrame = CFrame.new(workspace.CameraView.CFrame.X, Character.HumanoidRootPart.Position.Y, Character.HumanoidRootPart.Position.Z); -- Set the parts Y and Z to the player's position.
    Camera.CFrame = CFrame.new(workspace.CameraView.CFrame.Position, Character.HumanoidRootPart.CFrame.Position); -- Set the camera's CFrame to the part's position, and to look at the player's HumanoidRootPart position.
end)

The code above positions the part on its X and Z position, Which keeps it from moving back and forth or diagonally. However, we set the Y position of the part to the player’s Y position. Which allows it to go up and down.

Then, the camera’s CFrame is set to the part’s position, and to look at the player’s HumanoidRootPart position. Giving us a 2D camera.

There are many different ways to achieve a 2D camera without a part, but this is a good starting point. It can also help you learn the 2D camera concept visually.

I have another problem where I want to make the character auto run to the left.
I tried doing it but I failed.

local player = game.Players.LocalPlayer
local camera = game.Workspace.Camera

player.CharacterAdded:Wait()
player.Character:WaitForChild("HumanoidRootPart")

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

game:GetService("RunService").Stepped:Connect(function()
	camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,30)
end)

local Humanoid = player.Character:WaitForChild("Humanoid")

Humanoid.WalkToPart = game.Workspace.EndPart