Skip to content

Translating to/from World coordinates? #156

Answered by MrGVSV
shanesveller asked this question in Q&A
Discussion options

You must be logged in to vote

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 32.0, this should map like:

World Tile
(0.0, 0.0) (0, 0)
(32.0, 0.0) (1, 0)
(63.0, 0.0) (1, 0)
(65.0, 32.0) (2, 1)

Edit: Sorry math was completely wrong lol, should be fixed now.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@shanesveller
Comment options

@StarArawn
Comment options

Answer selected by shanesveller
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants