I am trying to do local multiplayer in 2D, so I decided to use a camera that is separate from the player. I wanted to make the camera 3D like Unity, but I can’t get it change position. Here’s the code:
func _physics_process(_delta):
var posavg: Vector2 = Vector2(0, 0)
for player in players:
posavg += player.position
posavg /= players.size()
camera.transform.origin = Vector3(posavg.x, posavg.y, 10)
And even though I set it to the middle of the scene, it’s always off to the side.
My guess is that you are trying to get to something that zooms in/out using a 3d camera.
I think using a 3d camera is a bad idea in this case. You are better of using a 2d camera.
To use a 3d camera you would have to take your 2d scene and display it in a 3d scene on a plane. Now, you would be able to move your 3d camera along that 3d plane that displays your 2d world.
In your example what I think you managed to do is to display your 2d world on the 3d camera, so when you move the camera you move the 2d world as well.
2D is always drawn, for UI etc., but it’s not relative to the 3D camera, that wouldn’t make any sense, so there’s no reason, or way, to use a 3D camera here, just use a 2D one