- Home /
generating a 3D terrain from a 2D tiled map
hi everybody, I'm pretty new with Unity but experted in C# language I'm trying to port a map that i've used in one game i made in XNA, that's a 2D top down map
look at this screenshot as an example (consider just the map) to understand how it's done actually
what I'de like to do, is use the map (that actually is composed by 3 files, 1 per layer, that specify witch tile to draw), plus a layer that gives the walkable tiles (1=walkable, 0 = non walkable)
actually the game is turn based and players are just jumping from a tile to the other.
The map is 502x502
I'd like to reproduce this, using the terrain in unity, but with some changes (maybe allowing player to move smoothly from a tile to the other, always honoring the walkable/non walkable
ok let me start questioning:
how can i generate a basic map from my files, as a base to work on its detail after it has been generated? I'd like to create a script that load my files in unity (using a menu) and load a starting point to work on, to prevent generating all from scratch
(i could change easily my files in order to just write if the tile is sand, grass, cliff, etc...) what would be the best approach to implement this?
I'd like to know how to create an empty terrain of 502x502 of size, and adding to it, as a first step a terrain which the height change based on the tile type (e.g cliff = 10, grass=2, sand = 1, road = 0, etc..) and smothing the edges if possible (but i can do this by hand)
then as a second step, i'll look at another file to place objects (trees, random flower/bushes on green tiles, etc...)
then as a 3rd step i should add something, to store that a specific tile (so a 1x1 area of the terrain) isn't walkable, so i guess i should add a box collider, placed at my x,y coordinate and with height from 0 to an high enough value? or to prevent an A* alghoritm to pass in a particular part of the map i've to use something different?
sorry if i've been a bit muddler on my request, recapping anyway the most important thing atm is to generate the basic map from my 2d tiled map easily without having to create it by scratch/hand, so i can then fine tuning it by hand in unity
thanks
Answer by bugmagnet · Nov 13, 2014 at 06:49 PM
The approach of trying to make a terrain to match a tile map is very unconventional.
If your goal is to get a 2D map to appear in 3D, might I suggest using Tiled to Unity?
Full disclosure: I wrote Tiled to Unity.
Answer by Jeff-Kesselman · Nov 11, 2014 at 10:12 PM
Unity3D really is not a tile engine. Its an image and 2D physics engine.
You can do a tile map, but its a lot of work. You will have to write your own loader and you will get the best performance if you assemble the entire map into a single texture at run-time.
The other option is to create a flat mesh at runtime of quads (made up of two triangles a piece) with UV coordinates of each tile in the set set for each quad.
Again, its a lot of work however you go and rendering individual quads will be much more expensive in terms of frame rate (though it will save you memory.)
you could map each tile to a terrain height if you want... but i doubt the results will be very sensible.
To do that look at Terrain.terrainData
thanks for your input but maybe i didn't explained me right. I didn't want to create a tiled map from my files, but just create a basic 3D terrain that i can fine tuning within Unity with its terrain manager, painting it with textures, etc... So ins$$anonymous$$d of creating that from scratch, generating the basic landscape from my tiles files would be handy
I'm not worried by the work to do, at the end i consider this a learning practice, i just would like to know who to create a terrain "block per block" according to my 2d map
Terrain.terrainData is the right direction, the problem is that i didn't found an indepth documentation about what i need