Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

2D Physics How colliders are generated

Discussion in '2D Experimental Preview' started by Iain-Lobb, Jun 3, 2016.

  1. Iain-Lobb

    Iain-Lobb

    Joined:
    Jan 11, 2013
    Posts:
    30
    At the moment unity just seems to make a new box shape for each tile:
    - do we have options to set sloped / different shaped tiles?
    - Lots of boxes in a row isn't ideal for unity's 2d physics as things can potentially catch on the joins - could the collider be created more magically so that surfaces (ie. floors and walls) are a single polygon edge?
     
    der_r likes this.
  2. Iain-Lobb

    Iain-Lobb

    Joined:
    Jan 11, 2013
    Posts:
    30
    Oh currently it uses the image data - interested to see what permanent collider solution is because that won't work too well
     
  3. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    I'm also interested in that. Right now for my little test project I have created sloped tiles by creating a prefab with a handmade polygon collider that I attach to a tile. I created a slope Tile layer so the slope tiles aren't included in the main polygon collider.
     
  4. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    My ideal solution would be a tile collision editor that can be accessed via the palette, kind of like in Tiled Map Editor. On some tiles one might only want an Edge collider, for instance (jump-thru platforms).
     
    Xepherys likes this.
  5. Iain-Lobb

    Iain-Lobb

    Joined:
    Jan 11, 2013
    Posts:
    30
    Speaking of Edge Collider - 1 way platform effector, it would be good to give it some thorough testing to ensure it is suitable for arcade style platforming gameplay - I believe currently there are problems if the character starts a jump while intersecting the collider
     
  6. Johaness_Reuben

    Johaness_Reuben

    Unity Technologies

    Joined:
    Jan 27, 2016
    Posts:
    253
    We experimented with editing the collision for tiles, but quite a few things to figure out before we have something to preview. In the meantime work is on going on the TileMapCollider2D. Currently uncertain when it will be ready but here's a sneak of what's in the works.

    TileMapCollider2D Video
     
    Xepherys and der_r like this.
  7. Iain-Lobb

    Iain-Lobb

    Joined:
    Jan 11, 2013
    Posts:
    30
    That's interesting! In the video you can see the spikes really want to be a separate thing so that they're interactable - would be good to have a standard way to add interactive objects to the grid
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,049
    Whilst not in the preview, the TileMapCollider2D will produce per-tile colliders from a TileMap and there's options already per-tile of how to turn a tile into a collider shape such as off, grid-shape, sprite etc. If you add a CompositeCollider2D you can blend multiple colliders including TileMapCollider2D together. How you separate your tile-maps, colliders and composites will be totally up to you. The trick will be using multiple tile-maps as 'layers' but you can also blend-in ad-hoc stock colliders into it as well.

    You can see various videos on my Twitter feed here: https://twitter.com/melvmay if you're interested in seeing more.

    Here's some of them:



     
    Sir-Spunky, rikey and der_r like this.
  9. Iain-Lobb

    Iain-Lobb

    Joined:
    Jan 11, 2013
    Posts:
    30
    This is amazing work! This should be in this preview - any idea when it will be available to test? Hard to feedback on the 2d tools until it's a full ecosystem
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,049
    Thanks, appreciate that. Unfortunately, It's still a WIP so didn't make the first preview but it's very close to complete, certainly for the next preview. The existing physics support for TileMap, as is stated somewhere in the preview release notes, is temporary and will be ripped-out and burned and replaced with the above. ;)
     
  11. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,274
    We need also colliders that only work one way, like in Mario you can jump from under a platform and you will land on it after going though it.
     
    awesomedata likes this.
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,049
    That's what the PlatformEffector2D will do. You'll need to separate behavioral layers though so you can attached any effector to that tile-map GO.
     
  13. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    869
    @MelvMay
    Is there any 3D equivalent of the new CompositeCollider2D for 3D geometry planned or in the works yet?

    I know it may be premature to ask, but I really do want to be sure we get something that makes the user-implementation easy as pie for both 3D and 2D jumpthrough platforms (and slopes) at some point! The only true 2D physics-engine stuff that's left to do after this is adding the possibility of poly-editing the meshes of our sprites to give us the ability to create FFD animation natively for our 2D sprite images -- and native integration with Unity's 2d collision system would be a huge plus in terms of ease-of-use and versatility! We can then finally animate individual sprite mesh vertices, and any in-game character or environmental physics and visuals imaginable truly would be possible (and easy!) to make in Unity without needing expensive special-made tools! :D

    The stuff mentioned here is some of the most difficult things to do, and especially to get right! I'm loving getting to witness how you guys simply crash through these problems with such elegant and user-friendly solutions! It's your hard work in the physics department that made me switch to Unity in the first place! Nobody else even comes close to you guys!
     
    Last edited: Jun 10, 2016
  14. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,274
    Is there a 2d character controller?
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,049
    Not AFAIK. Certainly it would be more complex to implement and probably more expensive to computer but it is a nice idea for sure.
     
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,049
    There are many out there available with various features. There isn't a new one that Unity provides in this experimental preview.
     
  17. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,274
    I would love it if unity made an official one, this would make a great starting point for people just starting to use unity 2d
     
  18. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    If you want to use Unity's 2D Physics, one of the earlier live training sessions has a great starting point. I don't like the feel of these physics-based controllers so I use raycasting and transform.Translate directly to move my sprites around. It also feels more "arcadey". It's a bit more complicated but I find it makes things like slopes and jumpthru platformers easier to handle. Feel free to DM me, happy to share.
     
  19. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    I'm testing out multiplayer using the new Tilemap system. Because of that, I need to "Build & Run" the game to be able to connect with a second player. Unfortunately, after building the game, the existing temporary physics solutions for tilemaps (attaching a Polygon Collider 2D) doesn't seem to work anymore. At least not when I attach it at runtime (for procedural generation). Is there a temporary fix for this, or do I need to wait for the real TileMapCollider2D? (looks amazing btw!)