Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SpriteTile, a fast dynamic tile system (RELEASED)

Discussion in 'Assets and Asset Store' started by Eric5h5, Dec 11, 2013.

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not all at the same time, but you don't need to change scenes to load new levels.

    --Eric
     
  2. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,168
    Hi Eric,

    I'm having trouble creating infinite levels using SpriteTile. Essentially, I'd like to remove the boundaries on the map. How would I go about doing this?

    Thanks,

    - Tate
     
  3. Arsonide

    Arsonide

    Joined:
    Nov 16, 2009
    Posts:
    43
    The tilemap only takes up as much as it needs to fill the screen. Boundary tiles are only added if you tell it to add them. There are many ways to accomplish infinite scrolling, but first how big does your map need to be? Spritetile can handle very large maps, it uses about eight bytes per tile in memory, so consider just making a large map.

    If that is not an option, what I have done is modify the procedural demo so that I keep track of his world position and his tilemap position. When his tilemap position gets within a certain margin of the border of the tilemap, I shift the player back to the center (0,0), and regenerate the tilemap around his world position. If you do it right, it's invisible to the naked eye. Make sure your tilemap is large enough such that you are not regenerating constantly, but small enough to take up as little space in memory as you need and small enough to generate quickly (larger maps will generate slower, and hitching might be noticed when you change zones), I use 300x300.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, shift and regenerate is what I'd suggest. You can potentially use GetMapBlock/SetMapBlock to copy/paste parts of the level as needed.

    --Eric
     
  5. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,168
    Thanks guys.
     
  6. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,168
    Hi Again,

    I'm currently using SpriteTile for a multiplayer game. I need to be able to convert MapData to a string so that I may send the mapData as an RPC. How would I go about doing this? Or, if you have experience with uLink, maybe you can suggest a better way of sending the map information from the server to the client.

    Thanks,

    - Tate
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    MapData has .map (short[]), .info (ushort[]), .orderData (short[]), .triggerData (byte[]), and .mapSize (Int2), so you can convert those to strings.

    --Eric
     
  8. Stellar_Magic

    Stellar_Magic

    Joined:
    Jun 18, 2014
    Posts:
    2
    This looks really interesting and promising, as I've been looking for a system like this for building a top-down RPG style game, but I've got some questions.

    For one thing, does this system allow for sprites to use normalized maps? I've seen a couple engines and examples that include sprites with normalized maps to make for good shadow and lighting rendering.

    How much information is or could be stored for each tile? I'd like to be able to store information like how much 'cover' a tile would provide, define if a tile is passable, impassible, or 'rough terrain', perhaps a form of heightmapping (similar to how the old Close Combat games did height mapping with just number values for areas), and maybe even be able to damage it during runtime (a dragon pouncing on a wooden floor should do something, after all).
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It uses the Unity sprite system, so that depends on whether you can make that do normal maps, which I don't know if it can or not.

    It already has passable/not passable, and you can get info on which set/tile number is used per tile and use that for various data, plus you can use triggers to store arbitrary numbers (0-255) per tile that you can use for any purpose.

    --Eric
     
  10. archwaykitten

    archwaykitten

    Joined:
    Jun 12, 2014
    Posts:
    14
    I'm still trying to allow my characters to walk behind terrain in a 2d top down game. I have some tile sprites that are taller than the grid they're placed on. The idea is that any part of the sprite that extends above its grid square will be the part that the player can walk behind (if she approaches it from the top).

    How do I ensure that the bottom left of my sprites line up with the bottom left of each grid space? I can change the pivot to the bottom left, but then when I place the tiles the bottom left of the sprite is placed in the middle of each grid space. I think I need to set the pivot of every tile sprite to bottom left and then also offset each sprite by half my standard tile size, but I can't figure out how to add an offset to these sprites.
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use the Unity sprite editor to edit the pivot points, if they're in an atlas. If they're single sprites, just change the pivot to custom and use the appropriate numbers for x/y. (They are normalized so 0.0 is always left/bottom and 1.0 is always right/top.)

    --Eric
     
  12. archwaykitten

    archwaykitten

    Joined:
    Jun 12, 2014
    Posts:
    14
    I can change the pivot points to bottom left, but that messes things up in the TileEditor window. The TileEditor window is set up so the pivot will always be placed in the center of the grid space I click on. I need it to place the bottom left pivot into the bottom left of the grid.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, change the pivot point to custom and enter the appropriate numbers, maybe something like (0.5, 0.25).

    --Eric
     
  14. archwaykitten

    archwaykitten

    Joined:
    Jun 12, 2014
    Posts:
    14
    The appropriate number will always be 0, 0 (or bottom left) since I want my pivot to be the bottom left always. Most of my tiles fit perfectly within the grid, and setting those pivots to 0, 0 causes them to be placed weirdly within the TileEditor window (because the pivot is always placed in the center of a grid space).

    The trouble is that my tiles might all be different heights. I can edit the pivot like you suggest (to something like .5, .25) and then continually adjust those values until that particular sprite is aligned to the bottom left of its grid, but I'd have to do that separately for every oddly shaped sprite I have. I'd rather just set everything to have the same pivot (0, 0), so I don't have to think about it. I'd like to control where the pivot is placed within the grid, rather than have it default to the center. Is there a way to offset the tiles in such a way?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You don't need to continually adjust the pivot, just set it once. Since sprites can be placed anywhere in the tile grid, it's really a requirement that you edit the pivot for oversized sprites. It's not something that can be done automatically since SpriteTile has no idea how you want to use any given sprite.

    --Eric
     
  16. archwaykitten

    archwaykitten

    Joined:
    Jun 12, 2014
    Posts:
    14
    I think I'm setting the pivots correctly. The trouble is that when I place a tile in the TileEditor window, it places the pivot in the center of each grid square. I want to place the pivot on the bottom left corner of each grid square so my tiles can be naturally aligned to the left and to the bottom, regardless of their size.

    For now, I've gone ahead and done what you suggested and manually adjusted the pivots on a few of my oversized tiles. This is working fine. The only trouble is that every different sized tile requires its own pivot value to be calculated and set, and I worry how that workload will scale when I have many more tiles to work with. If I could place the pivots in the bottom left of each grid square instead of the center, all of these pivot values could be the same (0, 0) and set en masse.

    Thank you for your help. I'm not stuck anymore. You've led me to a solution, even if it's not as elegant a solution as I was hoping for.
     
  17. Arsonide

    Arsonide

    Joined:
    Nov 16, 2009
    Posts:
    43
    Hey Eric, I implemented the layer method for recoloring some of the tiles, but after doing it, the inefficiency of the whole thing bothers me. (Small things bother me.) I think I will just wait on the next update. Do you have any indication as to when that might be?
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sometime this month, I hope.

    --Eric
     
    gruddlebug likes this.
  19. GreasyFox

    GreasyFox

    Joined:
    Jul 8, 2014
    Posts:
    2
    Ok, I have now read all of the messages up to this point, and should now be able to ask a specific question!
    I just want my tiles with collider set in the editor to not allow entry for my player character.

    I have tried experimenting with this this javascript: http://www.starscenesoftware.com/files_spritetile/charactercontrol.html
    But I am not skilled enough convert it to C#, and also to get it so the player doesn't move tile by tile.
    Here is my current script:

    usingUnityEngine;
    usingSystem.Collections;

    publicclassPlayerMovement : MonoBehaviour {

    Animatoranimator;
    publicVector2speed = newVector2(50, 50);
    privateVector2movement;
    intdirInt;

    voidStart (){

    animator = this.GetComponent<Animator> ();
    }
    voidUpdate (){

    floatinputX = Input.GetAxis ("Horizontal");
    floatinputY = Input.GetAxis ("Vertical");

    movement = newVector2 (
    speed.x * Time.deltaTime * inputX, speed.y * Time.deltaTime * inputY);



    NOTE: the rest of this script is just animation code...
    Can anyone please help on what to add to this script.. and if there is anything else I need to add to my standard tile.loadlevel script?
    Thanks in advance
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You kind of need to do tile by tile movement if you want to use GetCollider. If you're using physics colliders, then it's another matter and not actually SpriteTile-related; it's just standard movement which isn't really in the scope of this topic. Standard physics stuff really. (Please use code tags when posting code.)

    --Eric
     
  21. GreasyFox

    GreasyFox

    Joined:
    Jul 8, 2014
    Posts:
    2
    But how can it not be SpriteTile related if I'm importing all my sprites into your editor and marking them as triggers, colliders or simply texture?

    One final ever question then.. am I best to abandon using SpriteTile to create my maps, or am I just a bit of research from figuring out how to use it in a standard top down RPG, where the player doesn't happen to move tile by tile?

    Si
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What I mean is, if you're using physics colliders, then it's not really related to SpriteTile since there are no SpriteTile functions involved. You'd just be moving a character around and it would collide with physics colliders as normal. You can use the standard Unity OnCollisionEnter2D functions and so on.

    It would only be specific to SpriteTile if you're using a SpriteTile function such as GetCollider. But you haven't said which method you're using. In any case, certainly you can use it for a top-down RPG.

    --Eric
     
  23. theRiley

    theRiley

    Joined:
    Jun 7, 2014
    Posts:
    4
    Love this package, already jump started my game to new levels. Quick question that might help others later if you don't mind.

    1 - i'm loading one tilemap (level) at a time, but the game will consist of several of these "maps" the user explores
    2 - when the player hits a certain trigger id, i use that to load the next map using Tile.LoadLevel
    3 - i then position the player to a specific tile coordinates (so it looks like they just entered Map B from the door behind them)

    this works perfectly, all my maps were 20x20. However I have a problem when i use a smaller map.

    Map A - 20x20 exit door at 19,3 (bottom right)
    Map B - 10x10 exit door at 0,7 (top right)

    When the player walks from A to B it's fine, when the player walks from B to A I want to position the player to 18,3 just to the other side of the door, but i get this error:

    I assume it's because 18 is out of bounds / it's thinking the map is still 10x10.

    If i position the player somewhere else (lets say 5,5 then it works fine).

    Any ideas how to "refresh" the map size when a level loads?

    Thanks again so much!
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Glad you like it! I can't seem to reproduce that though...maybe you're trying to use the larger coordinates before the new level has loaded? I tried this:

    Code (javascript):
    1. var levelSmall : TextAsset;
    2. var levelLarge : TextAsset;
    3.  
    4. function Start () {
    5.     Tile.SetCamera();
    6.     Tile.LoadLevel (levelSmall);
    7.     Debug.Log (Tile.GetMapSize() + " " + Tile.GetTile (Int2(5, 5)));
    8.     Tile.LoadLevel (levelLarge);
    9.     Debug.Log (Tile.GetMapSize() + " " + Tile.GetTile (Int2(18, 3)));
    10. }
    11.  
    where levelSmall is 10x10 and levelLarge is 20x20, and it works as expected.

    --Eric
     
  25. theRiley

    theRiley

    Joined:
    Jun 7, 2014
    Posts:
    4
    Thanks for the fast reply. Your response made me analyze the order I was calling things:

    OLD / BREAKS:
    1 GetWorldPosition (passing in cords of where to start player on this level)
    2 LoadLevel
    3 Transform player

    NEW / WORKS:
    1 LoadLevel
    2 GetWorldPosition
    3 Transform Player

    Makes sense that I need to load the level before I Get World Position of the new map.

    Thanks again!
     
  26. Drommedhar

    Drommedhar

    Joined:
    Sep 24, 2013
    Posts:
    78
    Before I buy this I have a question regarding my project:

    I know already that it is possible to have multiple tilesets.
    What I would need now is, that I create a map based on a tileset and ingame/in editor I want to dynamically change from this tileset to a different one (like a dark one). So I can simply change the look from the graphics by switching the tilesets used to render the map.
    The tilesets would have all graphics at the same position on the texture atlas but would just look different.

    This would be something we need. I could code that in by myself, but before spending money, I just wanted to ask.

    Otherwise nice looking plugin. Definately worth the money I think.
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's currently not a built-in function to do that, but it's pretty simple:

    Code (csharp):
    1. var setDiff = 1;
    2. var size = Tile.GetMapSize();
    3. for (var y = 0; y < size.y; y++) {
    4.     for (var x = 0; x < size.x; x++) {
    5.         var pos = new Int2(x, y);
    6.         var tile = Tile.GetTile (pos);
    7.         tile.set += setDiff;
    8.         Tile.SetTile (pos, tile);
    9.     }
    10. }
    That would increase the tileset of the map by 1; changing setDiff to -1 and running the code again would revert it.

    --Eric
     
  28. Drommedhar

    Drommedhar

    Joined:
    Sep 24, 2013
    Posts:
    78
    Great. Thanks for the quick answer. Will buy the asset and maybe add some things I need to it. It would prove perfect I think
     
  29. PortableCow

    PortableCow

    Joined:
    Dec 31, 2013
    Posts:
    8
    Since update 2.2 I've been having some problems with the layers mechanic. I create a level procedurally with code and have two layers. My character is in the foreground layer and collides with other tiles in the foreground (I'm using physics colliders). My character is a drill and can destroy tiles which I detect using physics2d.linecast. The linecast is hitting on tiles in the background which I don't want it to do. I've tried changing the layer mask but it seems that Unity is only recognizing one layer and ignores the sorting layers. The weird thing is that my linecast is detecting tiles in the background but the tileinfo struct is returning set:0 tile:-1 which doesn't exist.

    I have two sorting layers. How do these layers correspond to the unity layers with respect to having a foreground layer, background, etc in the Unity 2D demo? When you add a gameobject with the editor window you can specify the layer for collision detection but creating my level with code doesn't allow me to do that. It seems like Unity is just treating everything as one layer since I'm colliding with both foreground and background objects. I also use Tile.addborder and I can't get this function to add the border to my top layer. My character still collides with that border though.

    I'd be happy to post some code if that would help (if my explanation is too confusing).

    Thanks!
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The layer order in 2.2 was reversed so the layers now use the same method as Unity. If you invert the sorting order layer then it should have the previous behavior. TileInfo(0, -1) is an empty tile.

    I'm not quite sure what you mean by this, since the editor window doesn't specify the layer for collision detection, and everything you can do in the editor window can be done by code. (Aside from adding tiles and groups into the database.)

    --Eric
     
  31. bdickason

    bdickason

    Joined:
    Apr 5, 2014
    Posts:
    1
    Eric, thanks for creating this awesome plugin. I purchased it a few days ago and have been enjoying building my first tilemap for my game.

    I was wondering if you'd consider putting the example code up on Github or your website so I don't have to load it into my project. Call me a weirdo, but I prefer not to have non-utilized code sitting around in the repo, and importing it into a new project means I have to close my game and load up the source in a new project to review how it works.

    Also, have you considered an Open Source license for SpriteTile? I'd like for anyone to be able to contribute to my game (which is licensed under Creative Commons Share-Alike Non-Commercial) but am worried that people won't be willing to each pay $30 (per-seat) if they just want to fix a bug or grab the game to try out contributing to it.
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you want, you can unzip the unitypackage files and get the scripts that way. The license on the Unity asset store can't be changed (except for free assets), so it's not possible for it to be open source. I'm afraid it's not compatible with open-source-ish projects.

    --Eric
     
  33. jammyt

    jammyt

    Joined:
    Jul 7, 2014
    Posts:
    12
    Hi,

    Firstly, great little tool, it's very useful, thanks a lot!

    I'm using the latest version from the Asset Store (v2.2.1) and I'm having a problem when calling SetCamera from different Unity scenes.

    I have a script which is on the camera of each scene:

    void Start ()
    {
    Tile.SetCamera();
    Tile.LoadLevel(level);
    }

    The first scene loads fine but when I load another scene the call to Tile.SetCamera gives a debug message saying the camera is already set and the new camera doesn't get set. When I move around my level the bottom left of the SpriteTile level is rendered but not the rest of the level.

    I've had a quick look at the code and SetCamera checks cameraInitialized but this is never cleared and therefore that is why the new camera is never set. Is this a known issue and is there a work around? I tried to setup SpriteTile using the scripts (instead of the dll) but I couldn't get it work for some reason, otherwise I would have just fixed the script myself.

    Any advice would be very gratefully received as it's limiting my prototype to just one scene at the minute.

    Cheers

    James
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'll take a look at that...in the meantime it definitely works if the camera isn't destroyed between scenes. Using the scripts instead of the DLL works; see page 3 in the docs.

    --Eric
     
  35. jammyt

    jammyt

    Joined:
    Jul 7, 2014
    Posts:
    12
    Thanks the reply.

    For some reason when I updated the TileManager script it deleted the other data from there. I had it in source control and so I merged it back in and all is good now running from the source.

    With regards to making the SetCamera work on a different scene (or when reloading the same scene) when the camera is deleted, I commented out this section of code and it works fine now:

    if (cameraInitialized && cams != null) {
    Debug.LogError ("Tile.SetCamera: Camera is already set up");
    return;
    }

    Maybe I've done something non-standard with my usage but at least it's working again for me now.

    Thanks again for a great tool!
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That won't actually work quite right if you use SetCamera again in the same scene, but I've fixed it for 2.3.

    --Eric
     
  37. jammyt

    jammyt

    Joined:
    Jul 7, 2014
    Posts:
    12
    OK cheers, thanks a lot.
     
  38. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    Eric,

    I purchased your tile map since the first release but I never face him to use in a game. I'm currently using tilemap from 2DToolkit but something is boring me there that might change me to SpriteTile.

    I haven't defined yet all tiles needed for my map, so I implement it on demand. If I need to add new sprites to tilemap I have to refactory everything and its painful, I can't just add a new sprite and the engine will recognize it.

    SpriteTile can I easily add new tiles for my tilemap and all back structure won't collapse?

    Thanks!
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, if you re-load a sprite atlas it will just add the new sprites and leave the other ones alone.

    --Eric
     
  40. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    Eric,

    I'm reading in tutorial that layers are arranged by Z axis, however for new Unity "2D" we can arrange tiles by sorted layer instead of Z axis, is it possible in SpriteTile?
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Layers in SpriteTile use sorting layers as defined in the Unity editor, so layer 0 uses sorting layer 0, layer 1 uses sorting layer 1, etc. Each layer can have an arbitrary z axis distance.

    --Eric
     
  42. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    Thank you so much for the quick reply. I noticed it on tutorial pdf now and sorry for dumb question. You also made a mention that we need to create sorted layer by ourselves due it can't happen programmatically.

    I'm reading all pdf before I do a bunch of maps. Now I'll check if I can replace a sort cell by a prefab on runtime and change map render position to desired position (it occurs from down left to up right I guess) on Tile.SetCamera();
     
  43. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    UPDATED:

    The wrong line:
    var tile =Tile.GetTile(newInt2(x, y));

    -----

    I'm trying to get a specific tile position (it is in layer 1 not 0) and replace it to player, however Tile.GetMapSize(1) is walking through layer 0 instead of 1, so I can't get the player tile position:

    My code so far:

    Code (csharp):
    1.  
    2. var mapSize = Tile.GetMapSize(1);
    3.  
    4.         for (var x = 0; x < mapSize.x; x++)
    5.         {
    6.             for (var y = 0; y < mapSize.y; y++)
    7.             {
    8.                 var tile = Tile.GetTile(new Int2(x, y));
    9.                 //is player tile?
    10.                 if (tile.set == 1 && tile.tile == 4)
    11.                 {
    12.                     var pos = Tile.GetWorldPosition(new Int2(x, y), 1);
    13.  
    14.                     Player.transform.position = pos;
    15.                     Tile.DeleteTile(new Int2(x, y), 1);
    16.                 }
    17.             }
    18.         }
    19.  
     
    Last edited: Jul 27, 2014
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Layer 0 is the default, so if it's in layer 1 then you should specify that:

    Code (csharp):
    1. var tile = Tile.GetTile(new Int2(x, y), 1);
    GetMapSize(1) gets the map size for layer 1; if you want layer 0 then do GetMapSize() or GetMapSize(0).

    --Eric
     
  45. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    I have fixed it before, but thanks btw.

    I'm using layer 1 to put all itens, all background tiles are on layer 0 by default. Is that a good practice, Eric? So when I have to replace items by prefabs I just do it on layer 1, I guess this is good way to Interact with your maps.

    I've checked all documentation and I didn't found anything to suit it: Is possible to choose the position that camera will render the map?
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sure, that seems fine.

    SetLayerPosition? Not quite sure what you mean.

    --Eric
     
  47. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    Your suggestion didn't work well for me, cause all collisions seems to lost all position reference and they don't translate to the new position. So I made this and works good so far:

    Code (csharp):
    1.  
    2. var camTrans = Camera.main.transform;
    3. camTrans.position += new Vector3(0, -.33f, 0);
    4.  
    Thanks again!
     
  48. ajfischer

    ajfischer

    Joined:
    Jul 27, 2014
    Posts:
    2
    Hi, I just bought this yesterday and it's pretty cool so far, but there's one thing I'm trying to figure out. When I use physics colliders, I want to figure out how to react with it. How can I use OnCollisionEnter2D(Collider2D other) with SpriteTile? I can't figure out a way to implement that method for each tile, nor can I figure out how to store data in the tiles so I can write code for a game object I know I can use that method for. I guess if I could store the data in the tile, then I can retrieve it from the parameter from OnCollisionEnter2D to see if it's the tile I want. Am I missing something? Read the docs several times and I still see nothing to do this.

    Code (CSharp):
    1.     void OnTriggerEnter2D(Collider2D other)
    2.     {
    3.         // how do I know I'm colliding with a tile?!
    4.         if (other.gameObject.tag == "Tile???")
    5.         {
    6.             GameObject.DestroyObject(other.gameObject);
    7.         }
    8.     }
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use GetMapPosition to convert from world to map coordinates, and use functions like GetTile to see what type of tile the objects are hitting. You could also potentially use SetColliderLayer to set a Unity layer number for the tile colliders, and check the layer number in OnCollisionEnter.

    --Eric
     
  50. ajfischer

    ajfischer

    Joined:
    Jul 27, 2014
    Posts:
    2
    Thanks...

    I think I'm missing something else though. How do you store custom data in the tiles? I'm not sure what the tile types are even supposed to be.

    How do you know it's a tile in the collision callback methods?