Search Unity

Question Tile instantiate prefab from chosen point

Discussion in '2D' started by tomer44532, Sep 27, 2022.

  1. tomer44532

    tomer44532

    Joined:
    Jul 12, 2019
    Posts:
    3
    I am using 2D tilemap and tiles that instantiate game object prefabs. like the one in the picture:

    What I am trying to do is to check if the tile of the tree is occupied by using tilemap.HasTile. The problem that I get the center tile (the one marked in red) instead the one I want (the one marked in blue).
    Is there a way to create some kind of offset to the tile, or choose from where the instantiated game object will be created (I basically want the game object instantiated from the blue, instead of the red).
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    The easiest way is to set the pivot point in the tree's sprite to somewhere near where the bottom mass of the trunk is. This is done in the Sprite Editor, which is now an installable package rather than built in.
     
    Dark_Seth likes this.
  3. tomer44532

    tomer44532

    Joined:
    Jul 12, 2019
    Posts:
    3
    Thank you
    It worked perferctly.
     
    Kurt-Dekker likes this.