Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputEventMouse.global_position doesn't return global position #25023

Open
razcore-rad opened this issue Jan 16, 2019 · 7 comments
Open

InputEventMouse.global_position doesn't return global position #25023

razcore-rad opened this issue Jan 16, 2019 · 7 comments

Comments

@razcore-rad
Copy link
Contributor

razcore-rad commented Jan 16, 2019

Godot version: v3.1.beta1.official
OS: Ubuntu 18.10

This can easily be seen by having a camera around & moving it and on a node place:

func _unhandled_input(event: InputEvent) -> void:
	if event is InputEventMouse:
		print(get_global_mouse_position(), event.position, event.global_position)

Output eg.:

(2398.499023, 814.499573)(1918.499878, 742.499939)(1918.499878, 742.499939)

event.global_position == even.position is true.

@timoschwarzer
Copy link
Contributor

Please add Godot and OS versions.

@bojidar-bg
Copy link
Contributor

Try passing the event through make_input_local

@razcore-rad
Copy link
Contributor Author

Try passing the event through make_input_local

Yah, that doesn't solve the issue and it isn't a practical workaround. You'd have to catch the event in the Camera2D node, adjust it with make_input_local on the root node (or first node under root) which then has to be at least Node2D to implement make_input_local. It's complicated

@razcore-rad
Copy link
Contributor Author

Ah! I think this is related: #12175. Well to me this is counter intuitive. I expected that event.position/global_position works as it does for all other regular nodes. If it's relative to viewport (if I understand correctly), it should be named something like viewport_position or mouse_viewport_position (although I assume it's on touch and other input types too), but definitely not global_position which implies a position in the world.

I'm not sure if this is documented. Now that I think about it, it does make sense to have inside of _input & _gui_input positions in regards to nodes for which we override these functions. But the names are confusing and can't we have them all as properties of InputEvent? relative_position (relative to node using _input/_gui_input), viewport_position and global_position/world_position?

@KoBeWi
Copy link
Member

KoBeWi commented Jul 3, 2020

Can anyone still reproduce this bug in Godot 3.2.2 or any later release?

If yes, please ensure that an up-to-date Minimal Reproduction Project (MRP) is included in this report (a MRP is a zipped Godot project with the minimal elements necessary to reliably trigger the bug). You can upload ZIP files in an issue comment with a drag and drop.

(I tried it in 3.2.2 myself and seems fixed, but I could do something wrong. MRP would be really useful)

@0Shie0
Copy link

0Shie0 commented Aug 12, 2020

@KoBeWi
Godot version: 3.2.2
OS: Windows 7

Bug still there, hope MRP will help
bug_event_position.zip

@theDoktorJ
Copy link

theDoktorJ commented Feb 20, 2024

I don't mean to beat a dead horse, but this bug still exists in 2024 and is completely unmentioned in the documentation. I've been trying to get a mouse click working, following the current documentation. I finally found this bug report and this workaround of using make_input_local. This is extremely counterintuitive and since it is not in the documentation examples, nobody would ever think to do it. I am using 4.2.1 Stable I also imported the previous MRP into 4.2.1 and it still represents the issue correctly. Also of note, the workaround of using make_input_local(event) still doesn't make the global_position parameter the same as get_global_mouse_position(), once the camera has been moved from it's initial position.
In order to replicate the functionality of get_global_mouse_position() with events requires something like this:

func _unhandled_input(event: InputEvent) -> void:
    if (event.is_action_released("left mouse")):
        var local_event: InputEvent = make_input_local(event)
        var click: InputEventMouseButton = local_event as InputEventMouseButton
        var mouse_pos: Vector2 = click.global_position + get_viewport_rect().position + position

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants