Need Support with 2D game

Hi! I want to create a Sandbox game, 2D type, but I want the camera from the player to be seen from above, I don’t want a top-down 2D game, I want it to be seen from above,idk if you know what I exactly mean… That means the camera should be somewhere up and be able to see a larger radius, such as the whole map, and not be able to see the player character itself, and the player to be able to move forward, further back, left, right, lower, higher.

An example of a game outside of Roblox,that describes my situation, is Brawl Stars or Clash Royale

Could you help me how to code this? And tell me the exact name of this game I want to make?

Thank you!

2 Likes

Are you talking about like a 2.5D game? I can then try to make a script to do that for you

2 Likes

I don’t know for sure what a 2.5D game is. But I think you know the game clash royale or brawl stars, well when you enter a match on brawl stars or clash royale your camera is fixed somewhere up and you can see 2D but ONLY FROM ABOVE. That’s the camera part I want.Also i want to be able to go with the camera left, right, front, back and up and down

Now you know what I mean?

3 Likes

Yeah, I do. (Sorry about the late response)

3 Likes

Is ok,dw about that thing,it happns

3 Likes

I dont have access to studio right now, but try this;

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local CAMERA_DISTANCE = 15
local CAMERA_HEIGHT = 10
local function updateCamera()
    if character and character:IsDescendantOf(game) then
        local characterPos = character.Position
        local cameraOffset = Vector3.new(0, CAMERA_HEIGHT, -CAMERA_DISTANCE)
        local cameraPos = characterPos + cameraOffset
        game.Workspace.CurrentCamera.CFrame = CFrame.new(cameraPos, characterPos)
    end
end

humanoidRootPart:GetPropertyChangedSignal("Position"):Connect(updateCamera)

updateCamera()

Try this in a local script in StarterPlayerScripts.

2 Likes

humanoid:GetPropertyChangedSignal("Position")? You made a mistake here…

I would suggest OP to use RunService, as it’s more reliable and better overall.

To OP:
Are you trying to make a 2d plane game but have the camera see a large area of the screen or something else? Can you please explain by making a diagram?

4 Likes

There’s an error:

Position is not a valid property name.

At the line of code:

humanoid:GetPropertyChangedSignal("Position"):Connect(updateCamera)
3 Likes

Yeah, do humanoidRootPart for that.

2 Likes

Thanks for telling me about that, I am not really good sometimes without studio.

It should be the HumanoidRootPart, I think

1 Like

No,i don’t want to make a plane game.I want to make a sandbox game,to create your empire and army and protect the city.And I want to make the game 2D and be able to manipulate the Camera(go:Forward,Backward,right,left go down(not be able to go below the map),and go up.

2 Likes

Yeah no worries. <3

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local CAMERA_DISTANCE = 15
local CAMERA_HEIGHT = 10
local function updateCamera()
    if character and character:IsDescendantOf(game) then
        local characterPos = character.Position
        local cameraOffset = Vector3.new(0, CAMERA_HEIGHT, -CAMERA_DISTANCE)
        local cameraPos = characterPos + cameraOffset
        game.Workspace.CurrentCamera.CFrame = CFrame.new(cameraPos, characterPos)
    end
end

gamw:GetService("RunService").RenderStepped:Connect(updateCamera)

updateCamera()

Here’s an updated code.

2 Likes

OH, GOD.

I’m getting spammed in the output with this error:

Position is not a valid member of Model “Workspace.AndreiTheScripter”

2 Likes
local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local CAMERA_DISTANCE = 15
local CAMERA_HEIGHT = 10
local function updateCamera()
    if character and character:IsDescendantOf(game) then
        local characterPos = character.Head.Position
        local cameraOffset = Vector3.new(0, CAMERA_HEIGHT, -CAMERA_DISTANCE)
        local cameraPos = characterPos + cameraOffset
        game.Workspace.CurrentCamera.CFrame = CFrame.new(cameraPos, characterPos)
    end
end

gamw:GetService("RunService").RenderStepped:Connect(updateCamera)

updateCamera()

Maybe that might fix it?

1 Like

Ah, I see. You can use UserInputService to see key presses and add or subtract the cameras position accordingly. I don’t have access to y computer so I am not able to provide full code but here is a basic idea:

movementDirection = UserInputService:IsKeyDown(Enum.KeyCode.A) and -1 or UserInputService:IsKeyDown(Enum.KeyCode.D) and 1 or 0,0,UserInputService:IsKeyDown(Enum.KeyCode.S) and -1 or UserInputService:IsKeyDown(Enum.KeyCode.W) and 1 or 0
camera.CFrame *= CFrame.new(movementDirection)

P.S please fix any errors as it’s almost impossible to type code on mobile.

Also put this code in a runservice loop.

2 Likes

I think I missed that message, but that seems to fit the idea.

1 Like

Uh, it works partially… There’s a problem, now the camera is fixed at an angle. It’s not fixed somewhere up on the map, so you can see the whole map…

1 Like

@lonely1and1afraid and @bluechristmas20181 What should I do so that the camera is left in the open air, but you can control the camera moving? In which direction does the camera player move? (left, right, down, up, front, back?)I mean the parent of the camera

1 Like

It kinda work.But i want the camera to be up, so that you can only see the map from above and other things, I don’t want you to be able to see the player itself

Here’s an example how it should look like the final result:

1 Like

and when the camera is like that you can manipulate the camera to go forward,backward,right,left,up,down.

2 Likes