0 votes

On the top level I have a Node2d where I want to capture the mouse position on a click event. However, something is messed up and I have no clue what. The following GDScript is attached to the node.

extends Node2D

func _unhandled_input(event):
    if event is InputEventMouseButton:  
        print(event.position)
        # (514, 309)
        print(event.global_position)
        # (514, 309)
        print(get_global_mouse_position())
        # (1, 4.5)

If I click close to the center (0, 0) I get for event.position and event.global_position
coordinates which are totally off. However, get_global_mouse_position() works fine.
All properties for the node are on default. What could cause such behaviour?

Godot version 3.2
in Engine by (12 points)

Keep in mind get_global_mouse_position() is not in screen space, it is relative to the canvas your node is in. i.e if you have a zoomed/displaced camera it will acount for that.

On the other hand I think event.position and event.global_position are not using the same coordinate space, but I don't have Godot around to test this.

@Zylann Thanks for commenting! The "problem" was indeed a camera node.

Please log in or register to answer this question.

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.