0

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

maheshg
  • 339
  • 2
  • 7
  • 17

2 Answers2

0

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

Andrew
  • 24,218
  • 13
  • 61
  • 90
0

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 ?

Benoît Lahoz
  • 1,270
  • 1
  • 18
  • 43
  • Yes ... It still gives same behaviour ... Restitution of wall =0, circular_body=1 ... Tried this combination – maheshg Sep 18 '13 at 03:19