Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I'm making a game and I need a particle to bounce off a line. I've got this so far:

public static Vector2f Reflect(this Vector2f vec, Vector2f axis) //vec is velocity
        Vector2f result = vec - 2f * axis * axis.Dot(vec);
        return result;

Which works fine, but then I decided I wanted to be able to change the bounciness and friction of the bounce. I got bounciness down...

public static Vector2f Reflect(this Vector2f vec, Vector2f axis, float bounciness) //Bounciness goes from 0 to 1, 0 being not bouncy and 1 being perfectly bouncy
        var reflect = (1 + bounciness); //2f

        Vector2f result = vec - reflect * axis * axis.Dot(vec);
        return result;

But when I tried to add friction, everything went to hell and back...

public static Vector2f Reflect(this Vector2f vec, Vector2f axis, float bounciness, float friction) //Does not work at all!
        var reflect = (1 + bounciness); //2f

        Vector2f subtract = reflect * axis * axis.Dot(vec);
        Vector2f subtract2 = axis * axis.Dot(vec);
        Vector2f result = vec - subtract;
        result -= axis.PerpendicularLeft() * subtract2.Length() * friction;
        return result;

Any physics guys willing to help me out with this?

(if you're not sure what I mean with the friction of a bounce see this:

share|improve this question
Wouldn't it just be a matter of multiplying the component velocity parallel to the surface by the desired friction? – tyjkenn Mar 11 '12 at 0:51
up vote 3 down vote accepted

Here's the physics answer. (I'm not sure exactly what bounciness and all refer to, but this should be easy to calculate)

Let's take a particle moving towards the wall with uy, and parallel to it with ux. It's coefficient of restitution is e (akin to 'bounciness', for perfectly bouncy it's 1. For normal items it's less than 1). Also, let the friction coefficient be m (The correct mathematical symbol for this is mu, represented as μ. But since that's visually similar to the 'u' value we're already using, we'll instead use 'm' for clarity). A friction coefficient is usually greater than 1.

Now, the resultant velocities will be:

  • vy = -euy
  • vx = ux + m(e-1)uy
share|improve this answer
there's something wrong here: after your edits, the friction coefficient no longer is taken into account... – Mac Mar 29 '12 at 5:53
@Mac: Oh whoops, I forgot that I'd used "m" for friction coefficient. To me, It looked like a dimensional error, since m usually refers to mass--I though I'd neglected to cancel it out. I had come to this question to quickly copy the formulae for use here, and the physicist in me evidently didn't like the dimensional error. – Manishearth Mar 29 '12 at 6:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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