After collision of 2 dots i want they make 1 dot with double radius so my code
world.on("collisions:detected", function(data) {
data.collisions[0].bodyA.mass *=2
data.collisions[0].bodyA.radius *=2
data.collisions[0].bodyB.mass = 0
data.collisions[0].bodyA.recalc()
data.collisions[0].bodyB.recalc()
})
Radius doesn't change and sometimes strange behavior that 2 dots dissapear at one moment.
Is my code correct?
You can't have a mass of zero. If you want try setting the mass to be really small.
You might also be having a problem with the renderer's views not being refreshed. This is easy, just set the
.view
on each body tonull
.I'd also recommend making your code more general by using one of the tactics described here: https://github.com/wellcaffeinated/PhysicsJS/wiki/Collisions
That way if you add more bodies to your simulation it'll still work. For example: