3

I wrote a simple program where i can move around some objects. Every object has a bounding box and I use hooke's law to apply forces to the colliding objects. On every tick, I calculate the forces, divide them by the masses, multiply by elapsed time to get the velocities and then move the objects. However, this leads to perfect elastic collision.

Each of my bounding boxes has a priority value. Lower priority boxes can't push higher priority ones. This is important, because I want to have immovable objects later on. I want my spring formula to work like a rubber ball that you let go of above the ground. In other words, I want to be able to control how much of the momentum gets absorbed (it's supposed to turn into heat energy afaik) in the collision.

How should I go about this in a real-time simulation? (a before-after formula is no good, the collision happens in a time interval)

PEC
  • 133

1 Answers1

2

You want to implement a coefficient of restitution. The common way of doing this with a penalty (spring-based) method is to modify your force depending on the relative velocity. You don't list how you estimate the closest distance between the two objects, but the main idea is to multiply the force (exerted on both objects) by $\sigma$, where $$\sigma = \begin{cases}1, & \textrm{objects are approaching}\\\textrm{CoR}, & \textrm{objects are separating}\end{cases},$$ where CoR is a number between 0 and 1 (closer to 0 for less bouncy objects).

By the way, the more principled way to handle immovable objects is to ditch the priority system, and give the immovable objects infinite mass.

user7530
  • 50,625
  • Thanks! I think I'll go with that. If both objects have a CoR value, how would I calculate the sum effect of those? – PEC Dec 28 '14 at 07:35
  • Ah, for heterogeneous objects colliding you'll have to pick a CoR for each pair of materials rather than for each material. One heuristic to start with would be to try taking the $\min$ of the two. – user7530 Dec 28 '14 at 07:38