Search Unity

Weird collision of Sphere with corner of cube

Discussion in 'Physics' started by danjv, Feb 17, 2016.

  1. danjv

    danjv

    Joined:
    Mar 5, 2015
    Posts:
    4
    Hi,

    I have encountered a weird problem with collisions on Unity. I have tried searching for it, but I wasn't even sure what keywords to use.

    This problem happens when I have two cubes side by side, and a sphere is rolling over them. Sometimes, the sphere will somehow jump, which leads me to believe that it may be colliding with the corner of the cube. However, this only happens sometimes (depending on the drag and speed of the sphere).

    Attached is an image showing the sphere in the air, after rolling between two scaled cubes (from left to right), and the scene used to generate said image. I hope someone can help me with this.

    Thanks,
    Daniel
     

    Attached Files:

    Tymianek likes this.
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    give the sphere a physics material with friction set to 0
     
  3. danjv

    danjv

    Joined:
    Mar 5, 2015
    Posts:
    4
    Unfortunately, this is not an option in the original application.

    EDIT: What I meant is that in the original game, where I found the problem, I don't want to do this.
     
    Last edited: Feb 21, 2016
  4. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
  5. danjv

    danjv

    Joined:
    Mar 5, 2015
    Posts:
    4
    The attached files are a minimal example of the problem I found while developing a small game. However, in this game, I want the sphere to have friction, and therefore can't do what you say.
     
  6. Adreqi

    Adreqi

    Joined:
    Dec 5, 2015
    Posts:
    5
    I have a similar problem (capsule instead of sphere) and tried the solution gorbit99 gave me. Since it didn't work, I'll watch this thread too, just in case you come up with something :)
     
  7. danjv

    danjv

    Joined:
    Mar 5, 2015
    Posts:
    4
    I found a solution that works for me: either set the "Default Contact Offset" value in the project's physics settings or the contactOffset attribute of the objects involved to a really small value (0.0001 seems to work).

    From what I understand, what causes the problem is Unity's collision prediction, which is controlled by this contactOffset attribute.

    EDIT: You might also want to try other solutions from this thread: http://answers.unity3d.com/questions/568974/sphere-collider-catching-edges-of-aligned-cubes.html
     
    Wappenull likes this.
  8. Adreqi

    Adreqi

    Joined:
    Dec 5, 2015
    Posts:
    5
    Default Contact Offset totally works, thank you :) I hope it does not have too much impact on performance though.
     
  9. DreamEnder

    DreamEnder

    Joined:
    Apr 12, 2011
    Posts:
    191
    I'm having this issue in my mini golf game. The courses are made from pieces that are snapped together. When I hit the ball it moves and then hits the connecting edges of two pieces thus making the ball bounce when it shouldn't be.

    I've set **Default Contact Offset** to 0.00001 and it doesn't help. My gravity is set to -50 but that doesn't seem to affect the collisions between pieces.
     
    Tymianek likes this.