Search Unity

Perfect collision with rigidbody

Discussion in 'Physics' started by aodonn, Oct 11, 2019.

  1. aodonn

    aodonn

    Joined:
    Aug 20, 2015
    Posts:
    6
    I'm having a problem when dropping in a sphere with a rigidbody and apply some forward velocity.

    The sphere is ontop of a grid floor (100x100) of Unity default cubes (with colliders).

    The desired outcome is for the ball to run along this surface as if it was one single surface/collider.

    What happens is the ball will sometimes get "caught" on the edges of these cubes (where they join) and will cause the sphere to jolt into the air.

    How am I able to smooth this out while keeping the modular floor design of cubes?

    Thanks
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    What have you tried so far? Have you tried to adjust the parameters in Project Settings/Physics? And have you tried different rigid body settings, Interpolate and Collision Detection, for example? Just throwing some ideas to air as I can't know what you have done so far.

    When you have tried these and nothing helps, then move on to debug your setup, draw out intertiaTensors, center of mass etc. to see that you haven't done something wrong or if something is bugging out for some reason. I'm not a physics expert but I'd first check out everything before trying to do some quick fix by adding something or start thinking about combining meshes or such...
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Unfortunately your expectation is incorrect as all those colliders with act individually and hitting an edge of the collider is possible, you won't just hit the "top" faces of those cubes. I deal with 2D physics and the same applies there too. You'd be better off using a mesh for your surface. In 2D we have the CompositeCollider2D to merge the geometry of 2D colliders so they're appear as continuous surfaces, that's not available for 3D.
     
    aodonn likes this.
  4. aodonn

    aodonn

    Joined:
    Aug 20, 2015
    Posts:
    6
    Thanks for the detailed and helpful response, I understand the surface being all one mesh would solve the solution, however, as I'm working with modular (randomly generated) level design, what would be the best solution/work around?
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    There's no workaround that I know of. @yant might have a suggestion for 3D however.
     
  6. aodonn

    aodonn

    Joined:
    Aug 20, 2015
    Posts:
    6
    Managed to find a solution for the time being:

    Edit -> Project Settings -> Physics -> set Default Contact Offset to 0.0001.

    If anybody knows a better solution please let me know.