Search Unity

Object falls through box colliders

Discussion in '2D' started by MJost, Jul 28, 2015.

  1. MJost

    MJost

    Joined:
    Jul 28, 2015
    Posts:
    11
    Hi there,

    I'm using "Tile Editor" that creates tiles for me that have a BoxCollider2D attached. Tiles are of course placed seaming less next to each other. I now have a small object (about 1 third of a tile) with a CircleCollider2D attached that should bounce of the tiles (box colliders). It does so, but when it falls exactly onto the edge between 2 boxes, it happens that it falls falls straight through.

    The falling object has a Rigidbody2D and when I debug OnCollision2D I can see that the normal points to the right instead of upward when the object hits the ground. That explains the falling through I guess...

    I have no idea on how to address this issue without breaking collision for other scenarios like corners or vertical walls.

    Any hints or ideas are appreciated. Thanks.
     
  2. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    I am not sure if your tile editor is homemade or something you purchased but I hope that each tile is not a separate game object, each with its own box collider. If your map is square or rectangular shaped and every tile has a box collider, you can easily improve performance & fix your problem by using a single map-wide box collider. However, if your map has holes in it (certain tiles that do not have colliders) then you should use a single Polygon Collider 2D for your map. If your map uses a chunking system or has different bounciness zones, etc ., well then again the solution will be different. It all depends on the system you currently have. You may have to extend some of Unity's base framework (like Polygon Collider 2D) and/or the tile system you are using.
     
    Last edited: Jul 29, 2015
  3. MJost

    MJost

    Joined:
    Jul 28, 2015
    Posts:
    11
    I'm using the plugin called "Tile Editor"... It seems that it does place a BoxCollider around every single tile.
    I don't have the time to write my own editor and I also don't have the time to manually place colliders.
    Is there another tile editor that creates more efficient colliders?

    EDIT: I also tried out "SpriteTile" now and it fails too wherever "Tile Editor" fails. Player gets stuck when walking over edges, small objects fall through connections. I guess the only solution would be replacing the BoxColliders with a complete PolygonCollider or EdgeColliders...
     
    Last edited: Jul 31, 2015
  4. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    There are 2 ways to build tile maps in Unity, currently. One is to use game objects for every tile, the other is to build meshes to represent tiles. The first method can fill the camera view area with tiles and update them as you move, or can be used with a chunk based system. The second (meshes) would definitely be used with a chunk based system. Which technique you use is up to you, but the most common approach is a mesh based system. Messing with Polygon Colliders can be a bit rough, especially since they have to be extended in order to provide the level of detail that mesh colliders provide. If you are going to go about changing things up, I would recommend going the route of meshes, chunks, and mesh colliders, but you said you don't have the time to write your own so, I suppose your game will reflect your decision here. Good luck either way, hopefully you get things working.
     
    theANMATOR2b likes this.