Translating to/from World coordinates? #156
-
Good morning, and thanks for the awesome crate! Does |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If your map's origin is (0.0, 0.0) and you're only concerned about basic top-down square tiles, then you should be able to just divide your world coordinates by your tile size (rounded down). let tile_size = 32.0;
let tile_pos = (coords / tile_size).as_uvec(); For a tile size of
Edit: Sorry math was completely wrong lol, should be fixed now. |
Beta Was this translation helpful? Give feedback.
-
@shanesveller We have now provided a whole bunch of stuff to handle calculating tile position. See: bevy_ecs_tilemap/examples/mouse_to_tile.rs Line 372 in eabd66e And: bevy_ecs_tilemap/examples/mouse_to_tile.rs Line 257 in eabd66e |
Beta Was this translation helpful? Give feedback.
If your map's origin is (0.0, 0.0) and you're only concerned about basic top-down square tiles, then you should be able to just divide your world coordinates by your tile size (rounded down).
For a tile size of
32.0
, this should map like:Edit: Sorry math was completely wrong lol, should be fixed now.