Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How to Create Custom Colliders for Individual Tiles in Tilemaps

Discussion in '2D' started by ImpromptuTriplet, Feb 20, 2019.

  1. ImpromptuTriplet

    ImpromptuTriplet

    Joined:
    Jul 18, 2018
    Posts:
    7
    So I'm working on a top down game where the character will be moving on top of the Tilemap. An example of a basic scene Tilemap is shown below:



    I need to be able to add colliders to specific tiles that have walls on them.



    For instance this above tile needs a collider on the wall portion (where the red follows would be the collider shape), but not on the brick floor portion because the player will be walking on that part. I can't seem to figure out how to go about implementing this custom collider shape however. Modifying the sprite outline to only contain the wall part actually prevents the part of the sprite not contained in the outline from rendering, so that's clearly not the right solution.
     
    UnderscoreA likes this.
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,533
    If I understand correctly, inspect the image.
    Tick Generate Physics Shape.
    Click the Sprite Editor button.
    Change the dropdown in the upper left from Sprite Editor to Custom Physics Shape.
    Click Generate. This will do a fair job of wrapping the collider edges around the sprite.
    Fiddle with the vertices to get it the way you want, then click Apply.
     
  3. ImpromptuTriplet

    ImpromptuTriplet

    Joined:
    Jul 18, 2018
    Posts:
    7
    Okay, it looks like that is working correctly. Now I'm curious how I would go about specifying the center tiles to have no Physics Shape / Collider at all. Simply creating a custom physics shape and then deleting all vertices of the generated polygon doesn't seem to work.
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,533
    Try unticking Generate Physics Shape, and make sure your tilemap renderer's mode is Individual.
     
  5. James976

    James976

    Joined:
    Feb 20, 2019
    Posts:
    6
    If you uncheck the box "physical shape" should all work.
     
  6. fnavarrensis

    fnavarrensis

    Joined:
    Aug 1, 2020
    Posts:
    9
    This was the perfect solution thanks a lot!!
     
    TonyLi likes this.