I am trying to create the formula for applying a bouncing effect to an element which is already slowing down by friction.

At the moment I have an element which moves in one dimension at speed "S" and every 20ms. The friction is applied multiplying "S" by 0.9 every frame (20ms). What happens when this element collides with an elastic rubber band?

To be honest, after bouncing I would like the object to stay connected to the wall.


1 Answer 1


First thing, inertia never "slows stuff down". It only resists changes in the speed of the body. It's a very common misconception. A body in motion, due to inertia, tends to stay in motion, in fact.

There are other resistive forces which reduce the speed, though (viscosity, friction, &c). They don't affect the bouncing (except for 2D bouncing on a wall with friction)

Anyways, bouncing takes a very short time, so you may assume it to be instantaneous. If the wall is fixed, just reverse the direction of motion. That's it. For a 2D system, reverse the direction of velocity in the perpendicular direction only. If you don't want perfectly elastic collisions, and you want friction, use this.

Edited question:

If it's a rubber band, then things get considerably more interesting and complex. The easiest thing to do is approximate the rubber band as a perpendicular spring at the point of contact, which exerts a force $-kx$ on the ball, where $k$ is some constant, and $x$ is the deformation of the spring (the distance moved by the ball after impact). So, every 20ms, decrease the forward velocity(increase the backward velocity) by $50kx$ in addition to your 0.9 factor. In SI units, $k$ is usually in the hundreds. Stop applying this force the minute $x$ becomes 0 again.

I don't see what you mean by "connected to the wall".. If you want it to stick to the rubber band, do the same thing as above, but reverse the direction of change of velocity every time $x$ reaches zero.

If your velocities, positions, etc are signed (i.e. positive forward negative backwards), then you won't even need to switch the direction. Then just do $v_{i+1}=0.9(v_i-50kx_{i,rel})$ every 20ms. Note that here, $x_{i,rel}=x_i-x_{rubber}$, where $x_i$ is the absolute x-coordinate, $x_{rubber}$ is the x-coordinate of the rubber band. Now, if you want the ball to bounce off, then just stop applying the new formula the minute $x_{i,rel}$ becomes zero or switches sign. If you want it to stay stuck, you don't have to do anything.

For less-rubbery walls, use the formulae in the link above. You may want to set $e=1$ in the formulae. Note that they are for a 2D collision.

  • $\begingroup$ Hi Manis, thanks for the reply. I definitely need to fix the question so that is all clearer. $\endgroup$
    – Nuthinking
    Mar 13, 2012 at 10:22
  • $\begingroup$ @Nuthinking: I added a bit to this answer which (I hope) solves it. $\endgroup$ Mar 13, 2012 at 10:51
  • $\begingroup$ with "connected to the wall" I meant after the bouncing it would gracefully stop at the limit. Practically, when the direction is inverted the first time, the object will reach the limit with an easing in out function (let's say Quint). In this case I would just need to figure out the duration of this last animation. I will try to build a javascript demo. $\endgroup$
    – Nuthinking
    Mar 13, 2012 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.