Displaying tiles in a 2D tile-based sandbox game

Hello,

i’m not sure this is the right section of the forum for this. I went to the Getting started and Community Learning sections but it doesn’t seem appropriate for this post.

First of all, i’m a beginner with Unity and 2D tile-base games. I watched videos such as https://www.youtube.com/playlist?list=PLbghT7MmckI4qGA0Wm_TZS8LVrqS47I9R
but there are some things i still do not understand.

Before that, let me explain a bit the project i’m working on :

  • It is a 2D sandbox game with tile-based world.
  • The project was done with Torque previously and is being ported to Unity.
  • The player characters’ dimensions are 3x1 tiles (height x width)
  • The creatures’ dimensions are variable (from 1x1 to 4x3 tiles)
  • The world has different sizes (from 500 x 1500 to 1000 x 5000 tiles)
  • Resource tiles adapt to their surrounding tiles : if a dirt tile is on an edge with grass on it and i place something on top of it, the grass will disappear and the dirt tile will change to look like that something is really placed on top of the dirt tile.

Now for my questions :

  1. If i use meshes to display many tiles in one object, how do i manage front and back tiles, along with all the tiems that can be dropped on the ground? Or even the creatures or the player that have animations?
  2. Given the size of the World, and that each mesh is limited to a number fo vertices, do i need to place as many meshes as needed to represent the whole world? Or do i only create one mesh the size of the player camera and move it around?
  3. Currently, objects use hitboxes for collision detection, but that displays odd behaviour with large objects such as trees that cover smaller plants right beside them and forcing the player to cut the tree before being able to harvest the plant. If i use meshes to draw all those tiles and items, will i still be able to apply custom solliders to the sprites?
  1. You can move mesh’s vertices in z axis or make new mesh for each layer.
  2. You shouldn’t update your mesh each frame (huge lag). You can create all meshes at once or keep meshes visible to camera (create new before camera, destroy meshes behind). You can also try to draw your tilemap on one quad using texture editing (might be faster than meshes)
  3. Every tile should have same square colliders, so you should cut larger objects to square chunks (like trees in terraria game)

Hello, thank you for your answer. Your answers for points 1 & 2 are clear and i can say i learned something today :).
However, your answer to the point 3, although it is applicable in many games, i am not sure it is applicable in my case. The project i’m working on is not an 8bit game with clunky sprites, but an HD game with high resolution images/sprites and plants all have irregular shapes spanning several blocks in height and/or width. Also, there is talk about making it possible to let the players add their own content later on, which means uncontroled sprites with wierd shapes. This all makes your solution unapplicable. I guess that in this case the best solution would be to create those plants as sprites so that unity can make colliders from the sprite’s shape?

@madks13
I’ve never seen game with irregular tile shapes (at least I don’t remember seeing one).
Making something like this breaks whole concept of tiles and makes everything much more complicated (and of course much harder to debug and edit).
You can simply restrict our map editor, for example: change last block of mario game style pipe to its entry automatically, make placing tree branch possible only if it touches trunk etc.
That’s the most popular and easiest approach.
You can also treat bigger sprites as normal unity game objects, but it’d cost you more work when you start doing custom editor.

Sorry, i must’ve not explained it properly : it’s not the tiles that are of irregular shape, but the objects that we try to fit into a tile-based world. The tiles represent only resources that can be mined or dug up. Everything else is of non-rectangular shape. The “everything else” is coprised of : players, enemies, plants, fluids, some objects (well all of them but most can fit into a single tile).