I’m a little lost. I’m trying to get a random location within the bounds of my current level.
I can ask the tilemap for it’s bounds, but then I need to know the tilesize, which seems weird. What’s the best practice here? Send a message to a level manager script asking for a random location, and have all that information in that? Is there any way to quickly get the size of the world?
If you want to use tiles, they should all be the same size. Otherwise, the tilemaps would be rather screwed up. Once you decide on a tile size that would be appropriate, like 64x64 pixel tiles in Minecraft, you can make a simple function like this:
local tilemap = {}
function get_random_pos()
tilemap.x, tilemap.y = tilemap.get_bounds() -- (your tilemap)
local new_pos = {}; new_pos.x = math.random(0,tilemap.x); new_pos.x = math.random(0,tilemap.y)
return new_pos
end