title: Object getting stuck when checking for bounce java libgdx
body: <p>I am trying to make objects bounce if the oldPosition does not equal the current position, however sometimes the ball gets hung based on the gravity. This is how I am checking;</p>
  
  <pre><code>    @Override
  public void react(int occurence) {
      super.react(occurence);
      /*Bounce*/
  
      cantBounce = Math.abs(position.y - oldPosition.y) &gt;= -.1f &amp;&amp; Math.abs(position.y - oldPosition.y) &lt;= .6f ;
      distanceOldCurrent = Math.abs(position.y - oldPosition.y);
      if(occurence == Tuples.HIT_BOTTOM &amp;&amp; !cantBounce){
          velocity.y = -velocity.y / 1.3f;
  
      }else{
          attemptRest(true);
      }
  }
  </code></pre>
  
  <p>This code means if the object hit something from the bottom then change to a negative velocity therefor traveling the other way and bouncing. The 'distanceOldCurrent` variable checks if it has moved more then .5 in either direction on the y coordinate to stop from constantly changing velocities and perfroming little bounces when it should just stop. However when the two balls in the simulation bounce enough times on the platform and on eachother, the little ball always gets hung. This can't be the code for the DynamicBalls fault because they have the same code, they are two instances of DynamicBall. Here is a picture of what happens.
  <a href="https://i.stack.imgur.com/v82WY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v82WY.png" alt="The velocity in the image is not of the orange ball"></a></p>
  
  <p>Here is the code for the <code>DynamicBall</code> <code>react()</code> method</p>
  
  <pre><code>    @Override
  public void react(int occurence) {
      super.react(occurence);
      /*Bounce*/
  
      cantBounce = Math.abs(position.y - oldPosition.y) &gt;= -.1f &amp;&amp; Math.abs(position.y - oldPosition.y) &lt;= .6f ;
      distanceOldCurrent = Math.abs(position.y - oldPosition.y);
      if(occurence == Tuples.HIT_BOTTOM &amp;&amp; !cantBounce){
          velocity.y = -velocity.y / 1.3f;
  
      }else{
          attemptRest(true);
      }
  }
  </code></pre>
  
  <p>And here is the code for the superclass of dynamic ball</p>
  
  <pre><code>        @Override
  public void react(int occurence) {
  
  }
  float elapsedTime = 0;
  
  @Override
  public void update() {
      oldPosition.x = position.x;
      oldPosition.y = position.y;
      if(!cantBounce)
      velocity.y += Globals.GRAVITY.y;
  
      if((velocity.x &lt;= .3f &amp;&amp; velocity.x &gt;= -.3f))
          velocity.x = 0;
      else
          velocity.x -= 0.11f * Gdx.graphics.getDeltaTime();
  
      if(canFall){
      position.y += velocity.y;
      }
      position.x += velocity.x;
  
  
  
      elapsedTime += 1 * Gdx.graphics.getDeltaTime();
  
  }
  
  public void attemptRest(boolean condition){
      if(condition){
          canFall = false;
      }
  }
  </code></pre>
  
  <p>Please like if you think I was detailed enough and more importantly please help! I will be very active for the duration of this question.</p>