I’m wondering how people would deal with a 3D tile based game. Where the player can seamlessly move between maps, see I’m making a system like this and want some opinions.
So how I plan on having it is that the maps are stored in image files with each color being symbolic of a location of a tile on the tileset(Alpha will denote the vertical position), like 255,255,255,0 is one tile 0,255,255,0 is another so on, I think it will be in one file for the whole map of a size like 1024x1024 but it will only load each part 32 tiles around the character.
But this is were the first problem happens, floats become less precise the further away from 0,0,0 you are (Or so I hear) thus at 1024,0,1024 it might be off by a lot (IDK if that is far enough or not?) So I might have to move the character back to the center after a while, though I would prefer not to do that, so that I can save the characters position and then load the parts of the map around the character. For example if the player is at 305,0,305 then 32 blocks in each direction around the character will be loaded.
Yep, experienced this problem with Stranded Deep’s procedural generation, the position values get less accurate and can really mess up some of the shaders. A simple solution would be to reset the players position at 0,0,0 whenever you go out of range and offset all gameobject parents in the world to that position, then saving all your data.
I would not save offsets as a Vector3 for a tile based game assuming the tiles are uniform. Collisions would not be an issue either(I assume?) since it’s tile based you’d probably be just seeing if the spot is occupied. I don’t see floating point imprecision having an impact on gameplay for a tile based game, only visuals and you’d need to be further away than 1024 in any given direction to see an impact.
This is assuming you’re just using Unity for graphics, which is what I’d be doing for a tile based game. You haven’t really given enough information, is the player moving from tile to tile etc or is it just for placing things in the world. Either way, it shouldn’t take you very long to find out if it’s going to be problematic or not, do some tests and google floating point imprecision. There is a lot factors, like how much you move characters by at once, how you will set their positions etc. It’s not about how far off from 0 you are, it’s about how many digits(for the lack of a better term) your float is trying to represent; 1024.5 is more accurate than 1.582732.
I think I am going to use Unity’s built in Character controller and colliders throughout the game as the grid is only for the placement of the world. This is due to the Character moving in increments of 0.0625 (each 1 unity unit is 16x16 pixels)(Tests have show this is accurate up until 999.xxx) so it more free movement then in most grid based games. This system would allow for partial covered tiles as well.
Accuracy is one thing and being visually noticeable is another. Test it without worrying about floating points and just see how it looks visually, don’t look at the numbers. Game programmers often cheat :).
Have you thought of using Tiled for it? I know it’s 3D but you can simply do it in layers if the map isn’t too deep in one direction. (I’ve used it with 16 deep and the artist was happy) The map files are in XML so easy to parse and import.
I wont settle for anything less then perfect! The character must move in increments of 0.0625(As if it kept being slightly off each time it could end up way off if the user plays for an extended period)
Actually, I might have it move in increments of 0.125(2 pixels) that way it is much less precise needed for floats, I’ll do some tests when I get home with this.
Is Tiled a program? I couldn’t find it on the internet? Could you please provide a link?
Keep track of the position by something like an vector that is just ints and when you need to update his position just multiply the vector you want by your scale.
Thanks for the link. That program looks good, but my maps are more 3D, and that is for 2D so I think it would be counter intuitive to have to to work with layers and make placeholder graphics instead of making a tile editor myself for the image based world.
Sorry, I’m not sure I know what you mean by “vector” in this context?
So like in pixels? So work it out so that instead of moving in increments of 0.0625, the character moves in pixels then every step the actual world position is calculated by going say “PIXELSMOVED * 0.0625” then using that position for the world position? But then how do I move the character taking into consideration collision and making sure that I don’t move inside a collider?
Do you know if floating point imprecision happens equally on all devices? On my computer with increments of 0.125 (2 pixels) are fine up until 10,000? It seems like a round number so I guess everything acts the same? That way moving in increments of 0.125 world units would be fine and I would just lerp between them? and when the player enters a building/enters a battle the character will be forced using the method you suggested to realign any slight differences that might happen throughout gameplay.
Or maybe I should not use Unities collision for collision but use triggers for events? Then have another layer of map kind of that depicts if the tile is passable, what level it is on, if it moves up a level or whatever? The issues surrounding this is it is not trivial to make things like different sloped ramps or what ever to make the character move upwards.
I have worked extensively on an infinite tile-based code, I have a problem with finishing what I do like a my brain gets tired of that particular code and then I can’t go near it for a while, I want to put it into the asset store and also want to add something is, I should really send in the simple version actually because it has a lot of research on it already.
Floatingpoint accuracy will be accurate to a distance of about 99,000 unity units, that’s 99 km, and it should still be pretty accurate at 20,000, and thereafter the mesh will be 10% wrong and more.
unity collision is fine, unity mesh Collider, when he have time, you can check out faster code based on checking individual objects position compared to your elevation formulas
what is more important is normals, unity normals on a good because they get fussy at the edge of meshes so this seems will be bad shadows, so you have to make a little code that calculates the normal of each pixel using elevation formula if you have a continuous elevation formula, which presumably you would have if you wanted a giant landscape.