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

get_local_mouse_pos() offset bug in the editor #1885

Closed
Tracked by #6276
ndee85 opened this issue May 12, 2015 · 8 comments
Closed
Tracked by #6276

get_local_mouse_pos() offset bug in the editor #1885

ndee85 opened this issue May 12, 2015 · 8 comments

Comments

@ndee85
Copy link
Contributor

ndee85 commented May 12, 2015

I try to write a small editor plugin with gdscript. In my script I need the mouse coordinates in 2d world space. There for I use CanvasItem.get_local_mouse_pos() which in general seems to work fine, but there is an offset which I think may be a bug.

Take a look at the screen attached. When I position my mouse at 0,0 the printed position is about 12,98. Which seems to be the exact dimensions of the upper left rect I illustrated.
This offset is set by a zoom of 100%. Whenn I zoom in, the offset gets smaller and when I zoom out the offset gets bigger!

local_mouse_pos_bug

@OlexiyKravchuk
Copy link

I'm not sure but I think you're confused get_local_mouse_pos () function with, get_mouse_pos () function when you specify to take the local coordinates it takes out from the node of your object instead of just the viewport, and the node they differ because that they are locally .. .

@reduz
Copy link
Member

reduz commented May 16, 2015

ah there is one extra matrix you need that you probably don't have access to, I need to figure out how to get it available

@ndee85
Copy link
Contributor Author

ndee85 commented Mar 4, 2016

I wanted to bump this issue. Would be nice if this gets fixed for the editorplugin overhaul.
In addition. This does not only not work for get_local_mouse_pos() but also for viewport.get_mouse_pos(). I think it is related to this fixes issud 08e0e64.

And probably the same matrix as in the fix above has to be multiplied with the mouse coords:

Vector2 Viewport::get_mouse_pos() const {

I get the viewport with: get_tree().get_edited_scene_root().get_viewport.

@remorse107
Copy link
Contributor

As soon as the video was posted demonstrating the "tool" keyword at the top of the script I immediately began to perform a test and noticed the same issue. There seems to be no way to guarantee the coordinates of the mouse position in relation to the scene's global 0,0 position. Works perfectly in game mode, but not in the editor.

@ndee85
Copy link
Contributor Author

ndee85 commented Mar 6, 2016

@remorse107 @reduz
I think the viewport is ingame always at position 0,0. Thats the reason why it works there. In the editor the 2d viewport is not at 0,0 and there for the printed cursor location has this offset.

@akien-mga
Copy link
Member

What's the status on this issue?

@akien-mga akien-mga added this to the 2.1 milestone Jul 20, 2016
@akien-mga akien-mga changed the title get_local_mouse_pos() offset bug get_local_mouse_pos() offset bug in the editor Jul 20, 2016
@akien-mga akien-mga modified the milestones: 2.2, 2.1 Jul 25, 2016
@ndee85
Copy link
Contributor Author

ndee85 commented Aug 21, 2016

@akien-mga
Status is still not fixed.

@reduz
Copy link
Member

reduz commented Sep 10, 2016

I don't completely understand this issue, you mention calling CanvasItem.get_local_mouse_pos()
Where and when do you call this?

@reduz reduz closed this as completed in b16f41a Sep 10, 2016
akien-mga pushed a commit that referenced this issue Sep 19, 2016
@akien-mga akien-mga modified the milestones: 2.2, 3.0 Dec 19, 2019
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

5 participants