You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a TileMap with scale set to other than the default (1, 1), the operations local_to_map and map_to_local don't return the correct values.
For instance, if a TileMap with scale (1, 1) and TileSet with tile_size (64, 64) is used, when calling local_to_map(Vector2(100, 100)), it should return (1, 1) as it refers to somewhere inside that tile. However, if the scale of the TileMap is set to (0.5, 0.5), the same call will return (1, 1) too, but (3, 3) is expected as now each tile of the TileMap corresponds to 32x32 pixels of the world, that is, the tile_size multiplied by the scale.
Similar to this, the reverse operation has the same behaviour. Calling map_to_tile(Vector2i(1, 1)) with scale set to (1, 1) will return (96, 96). When scale is set to (0.5, 0.5), the returned value is again (96, 96), when it should in reality be (48, 48).
This might be expected behaviour but it wasn't specified anywhere in the documentation. At least that I could find.
Steps to reproduce
1.- Create a TIleMap
2.- Make a call to local_to_map or map_to_local and note the result
3.- Change the scale of the TileMap
4.- Make the same calls and note that the result is the same as before.
I made a small reproduction demo to better show this.
It doesn't because it is in local coordinates, so the transform applied to the map is not considered, this is explained in the documentation. If you want it in global coordinates you need to apply to_local/to_global.
In the process of trying to solve this problem, I am in the process of updating the tutorial about the different coordinate systems and the transforms in-between: godotengine/godot-docs#6277.
Godot version
4.0 beta 10
System information
Linux
Issue description
When using a TileMap with
scale
set to other than the default (1, 1), the operationslocal_to_map
andmap_to_local
don't return the correct values.For instance, if a TileMap with
scale
(1, 1) and TileSet withtile_size
(64, 64) is used, when callinglocal_to_map(Vector2(100, 100))
, it should return (1, 1) as it refers to somewhere inside that tile. However, if thescale
of the TileMap is set to (0.5, 0.5), the same call will return (1, 1) too, but (3, 3) is expected as now each tile of the TileMap corresponds to 32x32 pixels of the world, that is, thetile_size
multiplied by thescale
.Similar to this, the reverse operation has the same behaviour. Calling
map_to_tile(Vector2i(1, 1))
withscale
set to (1, 1) will return (96, 96). Whenscale
is set to (0.5, 0.5), the returned value is again (96, 96), when it should in reality be (48, 48).This might be expected behaviour but it wasn't specified anywhere in the documentation. At least that I could find.
Steps to reproduce
1.- Create a TIleMap
2.- Make a call to
local_to_map
ormap_to_local
and note the result3.- Change the scale of the TileMap
4.- Make the same calls and note that the result is the same as before.
I made a small reproduction demo to better show this.
Minimal reproduction project
TileMap and scale.zip
The text was updated successfully, but these errors were encountered: