why does bounce increase in box2d when restitution=1

1k views Asked by At

I have created a dynamic circle inside a static box (four static walls to make a box). applied negative gravity to the world.

now the effect is the circular body should bounce off inner walls and eventually stabilize.

with restituion=1 the effect that i am getting is : bounce off the wall keeps on increasing and it never stops.

What am i doing wrong? I thought resitution=1 meant indefinite bounce(of same distance), but here bouncing distance is increasing gradually.

// create ground (box-type object)
function createGround(x, y, width, height, rotation) {
// box shape definition
var groundSd = new b2BoxDef();
groundSd.extents.Set(width, height);
groundSd.restitution = 0.0;

var groundBd = new b2BodyDef();
groundBd.AddShape(groundSd);
groundBd.position.Set(x, y);
groundBd.rotation = rotation * Math.PI / 180;
return world.CreateBody(groundBd);
}


function createCircleAt(x, y, r) {
var boxSd = new b2CircleDef();
boxSd.density = 1.0;
boxSd.friction = 1.0;
boxSd.restitution = 1.0;
boxSd.radius = r;

// add to world as shape
var boxBd = new b2BodyDef();
boxBd.AddShape(boxSd);
boxBd.position.Set(x,y);
return world.CreateBody(boxBd);
}

using box2d.js

2

There are 2 answers

0
Andrew On

Box2d does not give precise simulation. Putting restitution to 1.0 just makes the physic look 'close-enough'.

1
Benoît Lahoz On

I guess it depends of the restitution value of your walls. The ball is bouncing on a wall that has its own "behavior" and, if I remember well, it computes a ratio between the 2. Did you try changing the wall restitution value ?