Get mouse position relative to camera?

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

In my project i have a Camera2D following the player character around. I want the player to have a weapon that always points towards the mouse cursor, so I need a way to get the position of the mouse relative to the camera’s view.
I tried


but these don’t seem to be relative to the camera.
I also tried getting the global mouse position and offsetting it by the camera’s center, which also didn’t work.

Hi! those instructions were in the character’s script?

p7f | 2020-07-29 22:19

get_viewport().get_mouse_position() is local to the top left of the game window. You’ll need to get mouse position - half of the game window size + the camera position.

Magso | 2020-08-04 01:19

:bust_in_silhouette: Reply From: Mrpaolosarino

I used mine as: