dimanche 16 novembre 2014

PhysicsJS - Collision between two bodies never ends


Vote count:

0




I've got this simple js:



Physics(function( world ){

//Defining object
var renderer = Physics.renderer('canvas', {
el: 'viewport', // id of the canvas element
width: 500,
height: 500
});

var ball = Physics.body('circle', {
x: 250,
y: 250,
radius:10,
restitution: .8,
mass: 3,
vx: 0
});

var box = Physics.body('rectangle',
{
x: 250,
y: 350,
width: 50,
height: 20,
restituion:.5,
treatment: "static"
}
);

// Add them to the world
world.add( renderer );
world.add( ball );
world.add( box );

//Add physical behaviours
world.add( Physics.behavior('constant-acceleration') );//add gravity
world.add( Physics.behavior('body-impulse-response') );//make obdies bounce (react to impulse)
world.add( Physics.behavior('body-collision-detection') );//detect collision between bodies
world.add( Physics.behavior('sweep-prune') );
world.add( Physics.behavior('edge-collision-detection', //dectect collision with edges
{
aabb: Physics.aabb(0, 0, 500, 500),
restitution:.3
}
)
);


//START playing
world.on('render', function( data ){
var renderer = data.renderer;
});

// subscribe to ticker to advance the simulation
Physics.util.ticker.on(function( time, dt ){
world.step( time );
});

world.on('step', function(){
world.render();
console.log(ball.state.vel._[1]);
});

// start the ticker
Physics.util.ticker.start();

});


that creates a world with a static platform and a ball falling on it. Ball falls and bounces, then bouncing slows and slows but it never ends. I've setted restitution < 1 in the bodies attributes.


Where am I wrong?



asked 1 min ago







PhysicsJS - Collision between two bodies never ends

Aucun commentaire:

Enregistrer un commentaire