hunterloftis / newton

A playful, particle-based physics engine designed from the ground up for JavaScript.
917 stars 49 forks source link

inertia effect on particle #30

Open lo-fo opened 9 years ago

lo-fo commented 9 years ago

How would one add an effect of inertia on a particle ?

let's say i would like to improve the example from the guide (copy/pasted here)

var mousePin = null;

renderer.on('pointerdown', function(point) {
    var particle = sim.findNearest(point, 30);
    if (particle) mousePin = sim.add(Newton.PinConstraint(particle, point));
});

renderer.on('pointerup', function(point) {
   if (!mousePin) return;
   sim.remove(mousePin);
   mousePin = null;
});

And i would like the particle to continue its movement upon mouse release, and slowly stop until its completely static.

Since forces are applied globally on all particles, the way to go would be to make an inertia constraint to target a specific particle. Am i right ?