-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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_position does not work under certain circumstances #85705
Comments
Indeed seems like TileMap's global transform ends up in incorrect state. Recalculating it manually gives correct result which means it must be an issue with not marking it as dirty or something like that. In the MRP: var gt := Transform2D()
var ci: CanvasItem = tile_map
while ci:
gt = ci.get_transform() * gt
ci = ci.get_parent() as CanvasItem
prints(tile_map.global_position, gt.origin)
|
Thank you for confirming the Issue. |
Hmm. Might be due to some errors in computing the global position indeed. The TileMap node has some logic to handle animated movement and sync it with physics. I don't know what would cause it exactly though, I might need to investigate. |
This is my workaround for now: extends TileMap
func get_local_mouse_position_() -> Vector2:
var gt: Transform2D = Transform2D()
var ci: CanvasItem = self
while ci != null:
gt = ci.get_transform() * gt
ci = ci.get_parent() as CanvasItem
return get_global_mouse_position() - gt.origin |
Godot version
Godot v4.2.stable (46dc277)
System information
Godot v4.2.stable (46dc277) - Freedesktop SDK 23.08 (Flatpak runtime) - Wayland - Vulkan (Forward+) - dedicated AMD Radeon RX 5500 XT (RADV NAVI14) () - AMD Ryzen 5 5600X 6-Core Processor (12 Threads)
Issue description
If:
TileMap
TileMap
has aTileSet
TileSet
has anAtlas
Then:
get_local_mouse_position
is calculated wrongMore specific:
Under the said circumstances, to
get_local_mouse_position
the negatedoffset_left
and negatedoffset_top
is added which adds up to the wrong result.However, this does not happen if the
TileMap
has notTileSet
or theTileSet
has notAtlas
or if the scene is loaded directly.The behaviour should be consistent.
If the TopLeft corner of a
TileMap
is clicked,get_local_mouse_position
should return(0, 0)
.Steps to reproduce
See the issue description or the minimal reproduction project.
Minimal reproduction project
get_local_mouse_position-test.zip
The text was updated successfully, but these errors were encountered: