Make bouncier objects

Topics: Developer Forum, User Forum
Sep 7, 2009 at 5:53 PM

Hey,

In my game i have circle objects that use rectangle object to bouce around the screen, the rectangle objects need to have different bounce atributes.  I started using

_rectangleGeom.RestitutionCoefficient;

to make them more or less bouncier but this wasn't giving the desired effect cause it wasn't powerful enough so i decided to work something out in the onCollision eventhandler.

private bool OnCollision(Geom g1, Geom g2, ContactList contactList)
{

          if (g1.Equals(Pearls[i]._circleGeom))
          {
                  Vector2 normal = Vector2.Normalize(Pearls[i]._circleBody.LinearVelocity);
                  Pearls[i]._circleBody.ResetDynamics();
                  Pearls[i]._circleBody.ApplyForce(200000 * normal);
          }
          if (g2.Equals(Pearls[i]._circleGeom))
          {
                  Vector2 normal = Vector2.Normalize(Pearls[i]._circleBody.LinearVelocity);
                  Pearls[i]._circleBody.ResetDynamics();
                  Pearls[i]._circleBody.ApplyForce(200000 * normal);
           }

}

This is giving wierd collisions if they take place in a short space of time. Is there n e better ways of accomplishing what i want to do,

maybe i've missed somthing out in the engine that would handle something like this.

Coordinator
Sep 7, 2009 at 7:51 PM

What do you mean by "short space of time" and "weird collisions"?

RestitutionCoefficient is the one that controls the amount of force given back to an initial impact. (Newton's laws) You can set it higher than one to add force back into the reaction. Applying force yourself should also work, but giving it too high force values and thus a high velocity, you will get tunneling issues. (It depends on your physics simulator settings and time step). If you explain what reaction you get or take a screenshot of it I might be able to help you more.