Search Unity

General Questions about handling tile based games

Discussion in '2D' started by WhiteRabbyte, Jan 21, 2019.

  1. WhiteRabbyte

    WhiteRabbyte

    Joined:
    Jan 21, 2019
    Posts:
    2
    So I've recently started working towards getting a prototype game off the ground, and I'm trying to tie together the different things I've done. This is going to be stream of consciousness, sorry for any trailing thoughts.

    I am guessing the advantage of using tiles and tile maps is they are more performance friendly than having a game object for every tile (?), so that's why I'm starting to look into them.

    I have been making a perlin noise based map generator with some other maths thrown in for erosion and such, but haven't made it have functionality past generating a texture from the array it creates.

    I'll go through the array and based on value ranges insert tiles into a tilemap of the same size. I'm sure I can get that working no problem, but the issue there comes from child classes of Tilebase.

    Unity has a bunch of nice scripts for 4bit and 8bit bytemasking autotiles, but they use rotation to save on tiles needed (ex. TerrainTile uses 15 tiles instead of 48) so I will have to make my own child of Tilebase so I can get full range where I need it.

    Some of my largest confusion comes from implementing A* into the system. I'm new to Unity as a whole, so I'm confused what should be a component, what should be inherited, and what should be a reference. A* uses nodes for position and calculating movement cost when pathing.

    Should I make a separate script for the node logic and have it be a component of the tilemap which is a parallel array of nodes for each of the tiles, or should the nodes be inherited from Tilebase and just add the functionality on top of general tile behavior?

    My perception of this may be skewed and I might just be thinking of this all wrong.

    My other major point of contention is my "Units" they should be tasked to do jobs from a queue which will have a location and an action. depending on the previous section the units will path either to the target node location or tile, and then when they get there perform a callback action that contains the details of the job like animation to play, changes to the unit, or any other general effects.
    Should my units be respondents all under a single managing controller, or each have their own control and react to incoming messages?
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @Golbez22

    Well I did a little demo game for myself, to learn Tilemaps and I learned this. Note that I only had static Tile data, built once in Start, and then another Tilemap for tile based lighting.

    I think it's easiest to think Tilemap just as a display map / view. So you can have a visual tilemap, then scan it and do a logical map from it. Like you would draw a Pacman map using Tilemap palette and it's brushes, then runtime your game reads it and builds a table of zeros and ones for collision. By scanning the Tilemap, you can get the Tile Asset used as each spot, and use this to decide what you store into your logical map.

    I haven't yet looked into pre-made Tilemap examples nor Scriptable Tile, so there might be other ways to do things, but this worked for me.

    Edit. This article is linked in many places around internet:
    https://medium.com/@allencoded/unity-tilemaps-and-storing-individual-tile-data-8b95d87e9f32

    Although I can't recommend it, just have it bookmarked. And using Vector3's as dictionary keys might be a problem.

    The question about units probably gets more answers if you ask it in scripting sub-forum as a separate question, with some code you have so far.
     
    Last edited: Jan 22, 2019
    WhiteRabbyte likes this.