How to get Camera2D follow top down player with mouse rotation.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Newby

The way I have set up my camera is making it a separate node to the playera and telling the camera to follow the player position in _process

position += player.get_global_position

since adding it as a child make the camera always rotate.

It works but the following does get choppy when there are a lot of enemies on the screen. I there a way to get the camera to follow the player as a child without it rotating or is the a better way to get the camera to set its position.

:bust_in_silhouette: Reply From: Dlean Jeans

Try turning off the rotating property of the camera.

It’s should be off by default though. So while that’s definitely the right way to do it, also make sure the camera is centered on the player (so if it is a child of the player-node, it position should be (0, 0)). Otherwise you will get strange results. If you want to offset the camera view from the center, use its offset-property instead!

njamster | 2020-02-14 12:47

:bust_in_silhouette: Reply From: Sween123

You can have multiple cameras. One as a child node, and one somewhere else. To switch between the cameras, switch the property “current”.
Don’t know what you mean that adding it as a child will make the camera always rotate. It should follow the player and work well.

My player rotation depends on where the mouse is pointing, top down shooter, when i added my camera to the player as a child, since the player rotation will try to follow the mouse and sinve the camera is a child of yhe player it will rotate aswell and is very disorianting. With my current make shift solution the camera does follow the player but at times the camera lags a bit. Beside setting the camera as a child what other way are there for my camera to follow the player?

Newby | 2020-02-14 04:39

I see.
The camera will rotate as well because it’s the child node. You can rotate backwards, by that I mean when the player rotates for example, 60 degrees, rotate the camera for -60 degrees.
Definitely there can be other ways, but what is commenly used is to put the camera as the child node. It’s flexible. For example, you don’t rotate the whole player node, instead you just rotate its spirte or something. Or, you put a Node2D(or Spatial for 3D game) as the parent, when moves, move Node2D. Camera follows the parent node, and when rotate, rotate the player body. There are many ways. You can make changes according to how you want to arrange the scenes and how you construct your program.

Sween123 | 2020-02-14 05:59