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

TileMap.local_to_map and map_to_local don't consider scale #70833

Closed
PKGaspi opened this issue Jan 2, 2023 · 4 comments
Closed

TileMap.local_to_map and map_to_local don't consider scale #70833

PKGaspi opened this issue Jan 2, 2023 · 4 comments

Comments

@PKGaspi
Copy link

PKGaspi commented Jan 2, 2023

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 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.

Minimal reproduction project

TileMap and scale.zip

@AThousandShips
Copy link
Member

AThousandShips commented Jan 2, 2023

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.

@PKGaspi
Copy link
Author

PKGaspi commented Jan 2, 2023

Thanks for the clarification, this helped me understand better local vs global transforms!

@Sauermann
Copy link
Contributor

The problem about the distinction between global and local coordinates is documented in godotengine/godot-proposals#3866.

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.

@Calinou
Copy link
Member

Calinou commented Jan 2, 2023

Closing in favor of godotengine/godot-proposals#3866 and godotengine/godot-docs#6277, as this isn't a bug.

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

4 participants