Search Unity

[SOLVED] 2d pyramid of square bends on impact

Discussion in '2D' started by crouzilles, Nov 22, 2015.

  1. crouzilles

    crouzilles

    Joined:
    Nov 21, 2015
    Posts:
    25
    Hi guys,

    I believe this may be my first post on this forum, so hello all. I am an ex programmer working in Learning & Development, but I am still very much hooked to coding. I discovered Unity 2 weeks ago now, I have been watching tutorials and reading documents to assimilate as much info as possible.

    On to the problem. I have a 2D project, within which I have a pyramid made of squares. A ball falls upon the pyramid and the problem is that the pyramid bends.

    Now to show you what I mean, I recorded a short video which is available in the attached video.


    If you could let me know how to stop the bending from occurring, it would be great

    Regards
    Crouz
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    This is Box2D. Box2D uses impulse forces to solve the simulation. These impulse forces are calculated using the number of iterations you specify in the Physics2D settings. You can increase the number of iterations to help get to a more accurate solution quicker however there are also a few things that this won't resolve.

    One of the most important ones is when you're using large relative masses. Box2D recommends you use no more than a 1:10 mass ratio i.e. don't have a mass of 50 colliding with a mass of 1. Keep the colliding masses as close as possible. In most cases, it doesn't matter that much but, especially in stacking situations like you have here, it can.

    There's also the Baumgarte settings (one for non-continuous col-det and one for continuous col-det) here:
    http://docs.unity3d.com/ScriptReference/Physics2D-baumgarteScale.html
    http://docs.unity3d.com/ScriptReference/Physics2D-baumgarteTOIScale.html
    These control how fast overlaps (the blocks in the pyramid become overlapped) are solved. Setting this lower, slows down the speed of overlap solutions, setting this higher, speeds up the speed of overlap solutions. If you set them too high, it can lead to overshoot where the overlap is not only solved but additional gaps are produced because it moves out of overlap too far.

    As always, the existing 2D physics settings are a default set that work for most typical situations. There's no single 'correct' set to use. You'll also find that stacking situations are the most sensitive.
     
    Last edited: Nov 23, 2015
    theANMATOR2b and MoonJellyGames like this.
  3. crouzilles

    crouzilles

    Joined:
    Nov 21, 2015
    Posts:
    25
    Melvmay, thank you very much for your time explaining the reasons and possible tweaks to be made to minimise this problem.
    Regards
    Crouz
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    You're most welcome. Hope you get it working how you want.
     
  5. crouzilles

    crouzilles

    Joined:
    Nov 21, 2015
    Posts:
    25
    Do you know if these settings you talk about above would also solve the problem in the attached screenshot?

    I thought I was going mad when I thought I could see the bouncing ball enter the plank, so I decided to pause when it hits the plank, and I am pleased to say senility isn't getting a grip on me, not yet anyway. I would probably expect a little bit of overlay, but not something to that degree, any idea?

    Regards
    Crouz
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    The mass of the ball is 450 which is huge. This gives it a huge momentum which impulse forces are slow to alter. Against a static collider this is a 1:450 mass ratio!

    One thing you can do, apart from reduce the relative mass, is to turn on 'Continuous' collision-detection rather than the 'Discrete' you have now.
     
    Last edited: Nov 23, 2015
  7. crouzilles

    crouzilles

    Joined:
    Nov 21, 2015
    Posts:
    25
    Thanks MelvMay,

    As always, to the point and precise.

    The problem stopped once I reduced the mass about 10 minutes after I wrote the question, but I wasn't sure which setting had had the impact, so left the question open to be answered. Things are starting to make sense and I am getting a feel for the engine which is always a good thing I guess.
    I will look into the collision-detection type if I come across other problems in the future.

    Regards
    Crouz
     
    MelvMay likes this.