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_global_mouse_position() is shifted in the viewport's transform #73160

Closed
JohnEmhoff opened this issue Feb 12, 2023 · 3 comments · Fixed by #73188
Closed

get_global_mouse_position() is shifted in the viewport's transform #73160

JohnEmhoff opened this issue Feb 12, 2023 · 3 comments · Fixed by #73188

Comments

@JohnEmhoff
Copy link

Godot version

4.0rc1

System information

Linux

Issue description

This is a copy of #30215, as it seems it was incorrectly closed (or there's a regression).

When I use the get_global_mouse_position() in a normal scene, the coordinates are right, but when I use in a scene that uses a viewport container to render pixelated the scene, the coordinates are incorrect.

Steps to reproduce

Add a viewport node with a non-1:1 scale. Note that get_global_mouse_position returns the wrong coordinates.

Minimal reproduction project

scale-bug-4rc1.zip

@Sauermann
Copy link
Contributor

# mouse = to_local(mouse) # no effect?

In your MRP, it is correct, that to_local has no effect in this case, because TileMap has a default transform.
to_local is not affected by the viewport.

The SubViewport-setup in your MRP looks complicated. Doesn't look like a trivial issue to investigate.

@Sauermann
Copy link
Contributor

Sauermann commented Feb 12, 2023

Somehow you managed to bring the SubViewport into an inconsistent state in the editor.

SubViewportConteiner.stretch == true implies that SubViewport.size is set automatically by the SubViewportContainer.
However in your MRP you have

  • SubViewportConteiner.size == (2560x1440)
  • SubViewportConteiner.stretch == true
  • SubViewport.size == (640x360)

This will cause problems, as described in #66906, which fixed a different way to create an inconsistent state.

The following topics might also be interesting for you.

related to #61301
related to godotengine/godot-proposals#6221
related to godotengine/godot-proposals#1666

Currently the method that brings you as close as possible to your wanted functionality is to set in your MRP SubViewportContainer.stretch_shrink = 4
image
This will automatically scale the SubViewport to the size of 1/4 of the SubViewportContainer.

If this doesn't satisfy your requirements, I would like to suggest, that you describe your needed functionality in the form of a proposal in https://github.com/godotengine/godot-proposals

@JohnEmhoff
Copy link
Author

Thanks, I'll mess around and see if that fixes the mouse coordinates. This particular project was created in version 3.something then migrated to 4 which might explain how it got into such a weird state.

@YuriSizov YuriSizov added this to the 4.x milestone Feb 19, 2023
@akien-mga akien-mga modified the milestones: 4.x, 4.1 Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants