get the angle to player postion and mouse coordinate stop working when adding a Camera2D

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

Hi all!

I’m currently stuck on a little problem. My project is a 2D game, isometric tile map. I let you a screen to show you the global structure and the relevant code:

In the script of my player’s node I use this code to calculate the angle to rotate the player facing the mouse cursor:
var rot = get_angle_to(get_viewport().get_mouse_position())
The problem is, as soon as I add a Camera2D as child to the player’s node, this angle become wrong.

How I can fix this ?

:bust_in_silhouette: Reply From: fpicoral

The problem is that you are getting the position within the viewport. When you add a camera, you can “leave” the viewport, so it won’t work.
What you need to do is change you rot variable to get_angle_to(get_global_mouse_position())

exact same problem :confused:

EDIT/ My bad ! This fix the problem thanks !

doums | 2019-01-26 19:35