-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
get_global_mouse_position() is shifted in the viewport's transform #30215
Comments
Related (if not duplicate) to #29570 |
@KoBeWi I am experiencing the same issue but I am not attaching the viewport to the screen like in the issue you mentioned. Calling get_global_mouse_position() on a node inside of the viewport is giving some really wrong results. In my case, I have a node2d with a camera and I am calling get_global_mouse_position() on the node2d. To get the correct mouse position and to offset the camera I had to do this: BTW everything was working then I simply moved my level to be inside of a ViewportContainer/Viewport and then the inputs were off. |
@KoBeWi This issue is talking exclusively about the inputs in _input(event) and Controls inside the Sub-Viewports and my issue is about the mouse position in the scene inside the Sub-Viewports. @giulianob Yes, i'm calling get_global_mouse_position() from a node that's outside the Sub-Viewport, and as the coordinate is global, it works for nodes inside the Sub-Viewport. But if a camera2d, that's the current camera2d inside the Sub-Viewport, changes the zoom, the zoom is not applied in the get_global_mouse_position(). And yes, the Sub-Viewport nullify any _input(event) and controls inside it, I needed to connect (via signals) the _input(event) from a singletone to every node inside the Sub-Viewport So, there's somethings that need to be changed in future update I think. |
Can anyone still reproduce this bug in Godot 3.2.3 rc4 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. |
Attached is a project that reproduces this on 3.2.3.stable.official -- it draw a circle centered on |
I have a question regarding the behaviour of |
Are you asking to clarify or getting feedback for how the feature should work? If the latter, it seems to me that they should return the same world coordinate. I interpret this function as a way to answer the question, "Where in the game world is the mouse pointing?" but I'm not sure if that's correct -- the documentation isn't very clear: https://docs.godotengine.org/en/stable/classes/class_canvasitem.html#class-canvasitem-method-get-global-mouse-position |
Indeed the docs are not clear. I am asking to clarify. It is because the internal code depends on that function at many points. And all such parts, that are placed in a different Presently, ** |
Global mouse position should be relative to viewport origin. Moving window shouldn't affect it. Not sure about SubViewports. If users use SubViewportContainer, they'd probably expect that their mouse position is in screen space, i.e. relative to the topmost viewport. But maybe it's fine if it wasn't, as long as it's documented. |
For me in 3.3.2, resizing the window affects it if I am using a subviewport.
Is there a way to get the mouse position relative to the screen rather than the viewport? My case is a little odd, I am making a 2D game that is displayed on a viewport in a 3D scene with the viewport projected on a mesh instance tilted like 25º in order to give it a 2.5D perspective. Sorry if that didn't make sense. Using get_viewport().get_mouse_position does not work on either the 2D scene or the 3D scene which is the root. Oddly, the get_global_mouse_position works perfectly when the window size is at the project resolution, but not if I resize the window. Going to look into the stretch settings right now and see if that has something to do with it. otherwise, I will try and come up with a formula to adjust the Vector based upon the screen size |
If you mean screen as "global, including area outside game window", you can try using |
Seems fixed in 4.0 alpha7 |
Godot version:
3.1.1 stable oficial
OS/device including version:
Win 10
Issue description:
When I use the get_global_mouse_position() in a normal scene, the coordinates is right, but when I use in a scene that uses a viewport container to render pixelated the scene, the coordinates is inacurated.
Steps to reproduce:
-Create a scene that draws a circle of the global mouse position (to_local() to make it a local position).
-Put this scene in other scene that render with a viewport container (the child viewport node has the same game display size).
The text was updated successfully, but these errors were encountered: