If I wanted to have some extra information abou tthe specific terrain or area within a tilemap, what is the best way to handle this?
E.g. I would like the terrain to affect walking speed, or if the player is on a specific terrain, but they do not have item X in the inventory, they take damage while walking etc.
Is there a way to assign aditiional properties to parts of tilemap? Ideally this would correlate to the tiles used, e.g. Grass = medium speed, Cobblestone = high speed etc.
Thanks in advance for any suggestions!
you can do
if ( tilemap.GetTile( new vector3 (x,y,z)).name == "Grass"){
speed = 1f;
}
depending on the name of your tiles
for x,y,z you use your character position, you might have to do WorldToCell if your tiles are not 1 unit wide
Sounds good, thanks! I will try this out.
You can also create a scriptable object, have it derive from Tile (I have it derive from RuleTile) and add whatever functions you want to that.
Thanks for the tip, can you then still paint the map using tile palette with your scriptable objects?
Yep, because it derives from TileBase/Tile etc… having it derive from RuleTile allows you to use your custom tile as a RuleTile, if you wish to do so.
I use the tilemap for one thing, displaying the tiles. Everything about the tiles is stored in a class that is used to populate an array[,] that matches the size of the tilemap dimensions I want to have. When I need to know something about the tile in question, I get the position of the tile in the tilemap and then access the corresponding array object. The data sits in the object. I would suggest something similar for you.
Hi, thank you for your suggestion. That sounds like a very versatile approach, if I have a quite large tilemap, will this huge array not be a performance issue somehow? I was also thinking, if I want to save the current state of the game and let’s say the tiles have been changed since last save, would such an object help me to store it? Can I then serialize it/save it to a XML or JSON file? thanks!
yes and you should organize it by chunks so you can load only the terrain near the player. This allows for practically infinite world size(as large as the disk space you are willing to occupy)