Search Unity

Numerically Specify Physics Shape for Tilemap Sprites

Discussion in '2D' started by WindFrame, Feb 21, 2019.

  1. WindFrame

    WindFrame

    Joined:
    Nov 17, 2018
    Posts:
    2
    Hi All,
    I'm trying to create slopes in a Tilemap, so I'm using the sprite editor to specify a custom physics shape for my sloping tiles (as discussed a couple of times already in the forums). However, there doesn't seem to be a way to numerically edit these custom physics shapes, and it's quite hard to get them to line up properly when drawn freehand (image attached to show what I mean).

    The Unity manual page for custom physics shape suggests further refining the shape in the collider's component settings, but that's not possible in a Tilemap because the tiles don't all have separate collider components.

    Any help would be much appreciated.

    Tilemap_Colliders.PNG
     
    MegamaDev likes this.
  2. WindFrame

    WindFrame

    Joined:
    Nov 17, 2018
    Posts:
    2
    Quick update in case anyone was wondering. Since the points in the sprite editor snap to coordinates at the pixel level, I was able to specify my shapes exactly by zooming in and counting the pixels from the corner. Not ideal in my opinion especially for high res sprites or complex shapes, but it gets the job done.
     
  3. theindielawyer

    theindielawyer

    Joined:
    Mar 25, 2016
    Posts:
    21
    Thanks for this idea/solution! Just ran into the exact same issue, seems very odd there is no numerical editor but hitting 'snap' in the editor and zooming to individual pixels does seem to be the best way to do it currently.

    Snap.png
     
  4. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    77
    ...But certainly not the most convenient when your entire tileset is made up of solid-colored temp shapes :)
     
  5. theindielawyer

    theindielawyer

    Joined:
    Mar 25, 2016
    Posts:
    21
    Agreed - the best workaround I've found for this so far is opening the spritesheet in Photoshop/GIMP etc. and manually adding the lines in for where you want the collider to go on a seperate layer. Then, after adding in unity, removing them from the file. A headache but it works!
     
  6. LCStark

    LCStark

    Joined:
    Sep 13, 2017
    Posts:
    6
    In case anyone gets here from a search engine, like I did:

    There isn't a built-in Unity solution for this. If you want to manually input physics shape coordinates, you have to edit the `*.meta` files of your sprites:

    unityPhysicsShape.png
     
    unity_42arthursousa likes this.
  7. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    77
    Ahhh--I hadn't thought of that. Glad I've been trying that on some other things so I'm used to doing this~

    (Anyone coming from a search: it's not hard, just open them in your IDE/code editor of choice, they're plaintext on the inside. May have to search a bit to find the right set of coordinates, but if experience stands, they should be pretty close after the sprite's name.)

    (EDIT: Mind you, I haven't verified this. I could be wrong.)