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

2d - bouncing ball with physics material seems to gain energy somehow

Discussion in 'Physics' started by whistler, May 3, 2015.

  1. whistler

    whistler

    Joined:
    Apr 15, 2013
    Posts:
    15
    Hi all,

    I make a ball sprite add rigidbody2d and circle collider. want this ball to bounce forever (bouncing must be at the same height) so make a physics material set its friction to zero and give bounciness to 1, and my ball starts bouncing as expected.

    But it gains energy with each collision, ball seems to bounce to a higher altitude each time it collides with floor.

    Dont want this, how can I get rid of that extra energy?
    (I want my bouncing ball to keep the same height)

    (I can fix it with c# but dont want to use scripting. Physics material should be enough for this right?)
     
  2. Stef_Morojna

    Stef_Morojna

    Joined:
    Apr 15, 2015
    Posts:
    289
    I would try and play a bit around with the physic material of the object that the ball bounces off.
     
  3. whistler

    whistler

    Joined:
    Apr 15, 2013
    Posts:
    15
    you cant :) you need to be precise.
    even 0.001 miscalculation would effect all you game mechanics.

    smt is wrong with unitys physics calculation of rigidbody2d with custom material I believe.

    scenero is a bouncing ball with zero friction and zero bounciness with linear and agular drag to 0,
    and ball keeps on gaining energy with each bouncing. it is weird :(
     
  4. TippyEx

    TippyEx

    Joined:
    Jun 3, 2018
    Posts:
    1
    The solution for this problem is setting the Rigidbodys Collision Detection property to Continuous, this way Unity keeps a closer eye on the collisions, and catches them the instant they touch (this is slightly more processor intensive)

    The default setting for Rigidbodys collision detection is Discrete, which means Unity doesn't catch the collision at the moment it touches the second collider, so the object may be slightly inside the second collider, this adds a minuscule amount of force to the bounce as it is forced out of the second collider, thus not returning to the original height.
     
    Areckahn and Saganomics like this.
  5. fmontserrat

    fmontserrat

    Joined:
    May 24, 2015
    Posts:
    4
    Thanks a lot!
     
  6. suhaylmia

    suhaylmia

    Joined:
    Jan 4, 2019
    Posts:
    2
    Thanks