+1 vote

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:
https://ibb.co/n7YyCRD

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 ?

in Engine by (22 points)

1 Answer

0 votes
Best answer

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())

by (521 points)
selected by

exact same problem :/

EDIT/ My bad ! This fix the problem thanks !

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.