Search Unity

2D Terrain Collison

Discussion in '2D' started by BabushkaDev, Mar 4, 2021.

  1. BabushkaDev

    BabushkaDev

    Joined:
    Jan 26, 2021
    Posts:
    1
    I watched a tutorial to make procedural terrain generation with noise and that worked, thank god, but I need a collider on the terrain so that my player doesn't fall through it. Obviously adding a collision box won't work because I can't shape it around the terrain, so what am I supposed to do?

    Also I'm new-ish with coding so try not to force anything advance on me without explaining.
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    So your terrain generation isn't using cube-like sprites? If they aren't a standard geometrical shape, you can probably just use one or a few edge colliders2D and you can bend and stretch them as you need. Note, dont try to enclose an edge collider, just think of it as a 2D line that can bend.

    If they are just cubes, then just throw a box collider2D on the prefab.
     
  3. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    use the terrain generation code to generate the colliders