Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unintended bounciness when stacking colliders

Discussion in 'Physics' started by Drezus, Feb 15, 2016.

  1. Drezus

    Drezus

    Joined:
    Oct 14, 2013
    Posts:
    13
    Hi

    I'm currently making a Tetris-like puzzle game where pieces eventually end up stacked one above the other.
    I was considering using Unity's native 2D physics to speed things up, but there's this weird bounciness effect that happens when a lot of pieces are stacked.

    http://puu.sh/n99lo/ec118b039f.gif

    I can't comply with a lossy physics like that since it'll interfere with the game's way to calculate position, force and other kind of manipulations.

    Is there any way to completely fix this kind of issue? Is it something missing? I don't think that making a workaround such as locking the Y axis once a piece hits another works because it'd be too process-heavy for mobile devices. I'd rather have a cleaner way to resolve this through Physics 2D settings, if this is ever related to that anyway.

    Thanks for helping!
     

    Attached Files:

  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Physic material with no bounciness?
     
  3. Drezus

    Drezus

    Joined:
    Oct 14, 2013
    Posts:
    13
    Nope. Already messed around that too.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,321
    Box2D solves each box individually but it uses islands to solve groups of objects such as stacks. Stacking of objects is a complex topic but Box2D does well to create relatively large stable stacks.

    You can improve the stacking by increasing the frequency of the time-step (default is 1/50th sec) and increasing the number of solver iterations. Also ensure that the mass ratio stays low i.e. don't stack larger masses onto another and generally keep the masses low (Box2D recommends a ratio of 10:1).

    If you can't find a satisfactory configuration that gives you the stability/performance you want then maybe you can simply use kinematic bodies and perform casting to determine when an object should move/stop.
     
  5. Drezus

    Drezus

    Joined:
    Oct 14, 2013
    Posts:
    13
    That seems to make it a little better even though it increases physics processing which is pretty dangerous. I managed to get a desirable effect just by creating a simple collision script from scratch using raycasts, though. Thanks for the tips!
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It's the progressive nature of physics engines, they solve a bit each frame, otherwise they couldn't work at all on current hardware, so if you bear that in mind you can figure out how to patch in desired behaviour - it's common for working with physics in games :)
     
  7. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    davconde likes this.
  8. davconde

    davconde

    Joined:
    Jun 3, 2019
    Posts:
    1