Skip to content

Commit

Permalink
add commend on >2 particle collicions
Browse files Browse the repository at this point in the history
  • Loading branch information
kaliumxyz committed Feb 18, 2019
1 parent f58644e commit 55b62ed
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ const collisions = {
if (x > particle.coords.x - entity.mass)
if (y < particle.coords.y + particle.mass)
if (y > particle.coords.y - entity.mass) {
/* breaks down when more than 2 particles are involved
* scenario: particle A will hit B so it inverts its velocity.
* if afterwards it will hit C it inverts again, this causes weird behavior like particles phasing into eachother.
*/
entity.vol.x *= -1;
entity.vol.y *= -1;
const volX = (entity.vol.x + particle.vol.x) / 2;
Expand Down

0 comments on commit 55b62ed

Please sign in to comment.