Dcrew Posted July 29, 2019 Share Posted July 29, 2019 How can I convert tile x & y to world point x, y, z? Link to comment Share on other sites More sharing options...
Ultroman Posted July 29, 2019 Share Posted July 29, 2019 I can't find an actual function to do this, but try searching for the word "TILE_SCALE" in the game code (without the quotes). You'll get a lot of lines like this local x = (posX - mapWidth/2.0)*TILE_SCALE local z = (posY - mapHeight/2.0)*TILE_SCALE Link to comment Share on other sites More sharing options...
Dcrew Posted July 29, 2019 Author Share Posted July 29, 2019 Would I use TheWorld.Map:GetSize() for map width & height? Link to comment Share on other sites More sharing options...
Ultroman Posted July 29, 2019 Share Posted July 29, 2019 Probably This line appears all over the place around the word "TILE_SCALE" local map_width, map_height = TheWorld.Map:GetSize() Link to comment Share on other sites More sharing options...
Dcrew Posted July 29, 2019 Author Share Posted July 29, 2019 I've just tried and it works perfectly, thanks so much. To get a random point instead of the tile center would I use + math.random(-(TILE_SCALE -1), TILE_SCALE -1) ? Link to comment Share on other sites More sharing options...
Ultroman Posted July 29, 2019 Share Posted July 29, 2019 Since it probably goes in both directions from the middle of the tile, I think you need to halve the scale. local HALF_TILE_SCALE = TILE_SCALE * 0.5 + math.random(-(HALF_TILE_SCALE -1), HALF_TILE_SCALE -1) Btw, if you didn't know, Lua's math.random is inclusive of both given values, so math.random (4, 8) --> (a number from 4 to 8) So you only need the -1 if you don't want the resulting position to be at the edges of a tile. Link to comment Share on other sites More sharing options...
Dcrew Posted July 29, 2019 Author Share Posted July 29, 2019 This all works, thank you very much! Link to comment Share on other sites More sharing options...
Ultroman Posted July 29, 2019 Share Posted July 29, 2019 You are very welcome Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now