First of all, I'm not sure if this is the right site for this question, as it's actually a game I'm developing. However, I thought that this would be a common thing to need to know in games, so I put it here.

I'm programming a physics simulation in which I have a list of balls that are moving around. They have different masses and radii. I am trying to find an algorithm to make them bounce off each other when they collide. I've googled the problem and found lots of solutions for when the balls are the same mass (such as billiards), but none for different mass balls. It's not essential to the question but I'm programming this in JavaScript using p5.js

  • \$\begingroup\$ Searching "2d circle collision mass" turns up existing guides with solutions to this problem. \$\endgroup\$ – DMGregory Aug 31 '20 at 23:44
  • \$\begingroup\$ Thank you! I obviously didn't use the right search keywords. I haven't implemented it yet but it looks good. \$\endgroup\$ – ThatCoolCoder Sep 1 '20 at 0:32
  • 1
    \$\begingroup\$ To give an overall idea behind the math, you want to write 1) conservation of momentum, 2) conservation of energy 3) normal impulse (the impulse is in the direction of normals) equations for the two outgoing balls. That gives you the velocities. \$\endgroup\$ – Real Sep 1 '20 at 3:43
  • 1
    \$\begingroup\$ Having said that, once you write those equations you can write non-elastic collisions, with energy loss, for example constraining the outgoing energy to be E_out = 0.9 * E_in, which tends to make all balls move in the same direction (or stand still), losing their energy over time. \$\endgroup\$ – Real Sep 1 '20 at 3:46

Your Answer

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

Browse other questions tagged or ask your own question.