Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

2D Collider sinking into other 2DColliders. Makes game completely unplyable.

Discussion in 'Editor & General Support' started by StartUpStudios, Sep 6, 2014.

  1. StartUpStudios

    StartUpStudios

    Joined:
    Jul 14, 2013
    Posts:
    11
    I have a few objects. They all have 2D Colliders on them. Box/circle. After working for days getting the arena that the balls are in to rotate, I'm running into this problem. Everything's scale is 1,1,1. Reducing the mass of the balls slows the process down, but doesn't stop it. The balls have rigidbodies, but the walls of the arena doesn't. Adding them doesn't stop it either, it just messes up the physics. This breaks the game, and I can't figure it out. Min Penetration is set to .001. But changing it doesn't affect a thing. Please see screenshot.
     

    Attached Files:

  2. StartUpStudios

    StartUpStudios

    Joined:
    Jul 14, 2013
    Posts:
    11
    Each of those are an individual sprite. Does anyone think that perhaps building the arenas outside of unity then applying a mesh collider would be more stable?
     
  3. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    The less colliders the more stable the physics simulation should be, also upping the simulation rate should reduce the errors (rate of all through).
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,937
    How are you rotating the walls/arena?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Nope, because 2D colliders are a completely separate physics engine and won't interact with 3D colliders.

    --Eric
     
  6. StartUpStudios

    StartUpStudios

    Joined:
    Jul 14, 2013
    Posts:
    11
    How would you up the simulation rate?

    Hinge Joint. Motor controlled via script. Location set to zero in function Update() to keep it in position otherwise it will sink entirely. Rotation untouched. Rotating the Transform caused some seriously weird physical effects with the balls. So the only way to do it is through rigidbody. After spending two days to figure that out, rotations work great, except the balls sink.
     
  7. StartUpStudios

    StartUpStudios

    Joined:
    Jul 14, 2013
    Posts:
    11
    Any ideas?
     
  8. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Edit -> Project Settings -> Physics 2D

    Check the tooltips on the settings and try increasing the ones that sound like they improve collision simulation, but watch for performance impacts.
    e.g.
    Increase - Velocity Iterations
    Increase - Position Iterations
    Increase - Maximum Linear Correction * Sounds promising for your pass through problem.
    Increase - Maximum Angular Correction
    Decrease - Maximum Translation Speed
    Increase - Baumgate Scale * Detects overlaps
    Increase - Baumgate Time * Ditto

    But first take a snapshot of the defaults, and also test the settings on the target hardware.

    Have fun, note you may want to have fewer larger balls in your container to reduce the load on the physics simulation.

    Also there should be other much more informative information on Unity 2D physics settings on the webb.

    If you find some please link to help others, or if you find a solution please share.
     
  9. StartUpStudios

    StartUpStudios

    Joined:
    Jul 14, 2013
    Posts:
    11

    Thanks. I'll check those out. It doesn't make sense to me as to why Unity would have a problem with the number of balls. Because I have a prototype I made about a year ago in 3D (before unity implemented 2D) and it has more on screen, but runs fine. You would think that by being 2D, it would work even better.

    In any case, I will post back with what helps. If anyone else has any ideas, I'd still love to hear them.

    I just now noticed that the sharper the angle between the colliders of the walls, the faster the objects sink... If I have two walls flat. Nothing sinks, even if I double the number of balls in the arena.
     
  10. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,937
    If you can post small test unitypackage, would be interesting to test it..

    btw. which unity version you are using?
     
  11. StartUpStudios

    StartUpStudios

    Joined:
    Jul 14, 2013
    Posts:
    11
    Update. I tried creating my arenas in Ai and importing them as one sprite. Then applying a polygon collider. Still sinking. I thought for sure that would help. now on to changing the physics settings.

    How would I do that? Just zip it up and upload it somewhere?

    Unity 4.5.3

    Whats strange is that on a certain level, I have a triangle arena. And the balls fall through at an incredible rate. No matter the angle it's turned to. Although all the settings seem the same......

    Adding Polygon Col to the balls prevents them from falling through, but now they jump about.
    Reducing mass to .0001 stops them from falling through, but they still sink.
    Changing the Physics2D settings didn't change anything.
     
    Last edited: Sep 7, 2014
  12. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,937
    can export small test scene as unity package (so no need to post complete project)
     
  13. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194

    Just ran a quick test scene with the default settings and the balls all stay within the spinning wheel, even with two paddles. Although the balls do get compressed into each other.
     
  14. StartUpStudios

    StartUpStudios

    Joined:
    Jul 14, 2013
    Posts:
    11
    They stop collapsing into each other if you turn col detection to continuous.

    I still haven't figured out why it's doing this. And it's still game breaking. Anyone have any idea? Especially since its fine using 3D physics, but not 2D.
     
  15. StartUpStudios

    StartUpStudios

    Joined:
    Jul 14, 2013
    Posts:
    11
    Anyone have any ideas?

    So either Unity 2D is so bad at physics that it can't handle a simple scenario and breaks itself, or there's something small that's screwing things up that I just can't find.