Can't move a Camera3D with code

Godot Version

v4.2.2.stable.mono.official [15073afe3]


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.

Can someone help me, or is this just an issue with using a 3D camera in a 2D scene?

I haven’t played with 3D in Godot yet, but it might be the translation from 2D->3D making the problem. Note that this is guesswork on my part.

What I would do to test it out would be to use a proper 2D cam and see if your current code acts the way you want it to. Then go from there.

A 3D camera doesn’t interact with 2D transforms, so you can’t move the camera and have the 2D rendering move, because 2D and 2D are entirely separate

Somebody correct me if I am wrong…

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

See here and here for split screen logic examples