I'm trying to create bouncing balls with realistic physics. At the moment, when the balls hit each other, they bounce back in the same direction they came from. How do I make them more realistic?

I don't know much about physics. What things should I be reading about?

Here's an image of how I imagine balls would bounce in real life:

how I think it should work (original source: http://thewombatguru.nl/Bouncing.png):

enter image description here

Is this how it works?

  • \$\begingroup\$ You might want to read about how elastic collisions work and some collision detection techniques to simulate them. \$\endgroup\$
    – Anko
    Commented May 18, 2015 at 11:21
  • \$\begingroup\$ I removed the code, since it seemed to belong in a different question. (It's still in revision history if you need it.) We have a sister site specialised in code review questions, by the way! \$\endgroup\$
    – Anko
    Commented May 18, 2015 at 11:29
  • \$\begingroup\$ @Anko I asked it there, they referred me to stackoverflow... well thanks anyway :) \$\endgroup\$ Commented May 18, 2015 at 11:34
  • \$\begingroup\$ The direction of the impact force goes from the point of collision through the center of the circle... \$\endgroup\$ Commented May 18, 2015 at 15:49

1 Answer 1


It kinda depends on what you're making.

If you're making a game about physics, you could conceivably write your own physics engine, however I do not recommend it. There are many 2D and 3D physics engines already out there that you can use that will save you months of work.

My first time using Box2d was intimidating, and I'll admit it has a fair learning curve. However unless you're a physics genius, the amount of time you spend figuring out Box2d will be significantly less than the amount of time you'd have spent writing your own physics, and I can guarantee the results will be better.

If you insist on writing your own physics... well you've been warned :P There are many articles online about 2D ball to ball collision, you'll just have to do the hard work of converting articles to code. If you aren't worried about spin, it's not too unreasonable of a job... but it will still be a lot of work.

Good luck!

  • 2
    \$\begingroup\$ Idk man, I wrote my own 3D physics library and that only took a few months. I wouldn't completely knock the idea. \$\endgroup\$ Commented Jun 18, 2015 at 7:39
  • \$\begingroup\$ Spin isn't difficult. Find the collision point, project it onto the collision vector, and push in that direction. For spin just spin it that way (CW or CCW) with an angular velocity proportional to the distance from the collision point to the projected point. For 2D games, physics is pretty simple. Also, Verlet integration is your friend. \$\endgroup\$
    – 3Dave
    Commented Jul 27, 2018 at 20:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .