Mouse problem after moving Camera2D

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

[->Plz don’t flame me for my english :slight_smile: <-]
Hello guys! I started a new project ,a top-down 2D shooter.
I was finding a way to move my camera so that it follows the player (a circle).

Simply with this code in the main node of the scene:

camera = $Camera2D

i add the camera as a child to the player so that it follows the player.

After this i change i’m having a problem with the rotation of the player, the player simply looks at the position of the mouse using this code:


and i noticed that the player rotates but not in the direction of the mouse,
who could help me?

Dont know why your vode is not working, but i always use get_global_mouse_pos instead of what you provided… does it fails with that too?

p7f | 2018-12-30 21:15

So i think to know why it’s not working, simply: self.get_viewport() gets the mouse position in the viewport and not in the game world. This means that if the camera changes position for example to x:3000, y:3000(the center of the camera) and the display size is 1024x600 when we move the mouse to the center of the display we’ll get 512(1024/3), 300(600/2) and not 3000, 3000 because this is the position of the mouse relative to the display and not to the game world

PS: get_global_mouse_position works

Chisk3n0 | 2018-12-31 12:38

Great if its works! I’ll post as an answer so others can see it’s resolved. If it helped you, please select it!

I think your explanation is correct.

p7f | 2018-12-31 13:20

:bust_in_silhouette: Reply From: p7f

Use get_global_mouse_position() instead of self.get_viewport().get_mouse_position().