Search Unity

Programmatically create an isometric tile collider in Sprite Editor

Discussion in 'Scripting' started by CraftedGaming, Mar 23, 2022.

  1. CraftedGaming

    CraftedGaming

    Joined:
    Jun 9, 2017
    Posts:
    37
    Let's say I have a block sprite and I want to make the bottom of it to be the new physics shape of the sprite. how could I achieve this?

    upload_2022-3-23_14-9-54.png
    I'm fairly aware that the sprite editor has a generate button which creates the collider automatically. I was wondering if there's available functions for us to modify and to use so that I could create this custom collider shape.

    I tried copy-pasting the collider from one sprite editor to the other but it didn't work out as expected. Maybe an added feature of this would be nice. But again, that's a topic for later.
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,647
    Could you use a prefab with a set collider for your Sprite already instead of generating one? I don't know anything about the method you were trying to achieve though.
     
  3. CraftedGaming

    CraftedGaming

    Joined:
    Jun 9, 2017
    Posts:
    37
    that actually makes sense. thanks. I'll do that in the meantime as I find a plausible solution for the one I'm asking.

    -
    edit: I used the isometric tile sprite that Unity provided. Generated the collider for it and adjusted it so it snugly fits the tile. Created a new game object with a polygon collider 2D and a sprite renderer. Placed the isometric tile sprite into the SpriteRenderer and reset the polygon collider to get the tile shape. Copied the polygon collider. Pasted the values into the polygon collider of the current game object that I need.
     
    Last edited: Mar 24, 2022
  4. CraftedGaming

    CraftedGaming

    Joined:
    Jun 9, 2017
    Posts:
    37
    I just found some buttons in the Sprite Editor if you expand the window a bit more. Might be useful for other people if they already made the physics shape for one sprite. See the Copy and Paste buttons beside the Generate button.

    upload_2022-3-30_19-48-24.png