¿How can i make a 2D camera?

                               Thanks you for reading

Hello developers, i’m trying to make a 2D game on roblox without any 3D objects.

I made a 2D movement:

And this is the script:

local World = script.Parent -- This is a screengui
World.IgnoreGuiInset = true
World.Parent = game.Players.LocalPlayer.PlayerGui

local Player = World.Player

-- player's movement

while wait() do
	if UIS:IsKeyDown(Enum.KeyCode.D) then
		Player.Position = UDim2.new(Player.Position.X.Scale + 0.01,Player.Position.Y.Scale,Player.Position.Y.Scale,Player.Position.Y.Scale)
	end

	if UIS:IsKeyDown(Enum.KeyCode.A) then
		Player.Position = UDim2.new(Player.Position.X.Scale - 0.01,Player.Position.Y.Scale,Player.Position.Y.Scale,Player.Position.Y.Scale)
	end

	if UIS:IsKeyDown(Enum.KeyCode.W) then
		Player.Position = UDim2.new(Player.Position.X.Scale,Player.Position.Y.Scale,Player.Position.Y.Scale - 0.02,Player.Position.Y.Scale)
	end
	
	if UIS:IsKeyDown(Enum.KeyCode.S) then
		Player.Position = UDim2.new(Player.Position.X.Scale,Player.Position.Y.Scale,Player.Position.Y.Scale + 0.02,Player.Position.Y.Scale)
	end
end

----------------------------------------------

-- Camera?


-------------------

Now, i don’t know how to make a camera that follows the player which is the “Red cube”

If you guys need more info, tell me. Have a nice day :smile:

1 Like

I believe you can just set the camera type to Subject from the onset, and choose the red box as your “subject” and it will remain fixed on it… see the documentation and examples here:

https://developer.roblox.com/en-us/api-reference/property/Camera/CameraType
https://developer.roblox.com/en-us/api-reference/property/Camera/CameraSubject

This will ofcourse keep it like this indefinitely… if you require it only sometimes, then script this setting in.

i’ll check that, but i think that i need a humanoid for that…

No you dont need a humanoid… you can choose a basepart.

You just select and input your basepart here where its highlighted:

I mean, there aren’t any baseparts, there are Frames

This is all UI?

If thats the case, then i would imagine creating a frame where the red box is always centered… and you move that frame, instead of the red box… or rather, the background behind that frame, so the red box always stays centered