phys2d bug with restitution? *youtube link added*

ok so i managed to get the restitution thingy working at last (after looking at the demo source)

then i found out something…

if you drop a bouncy ball in between a couple of sloping walls the ball will jump away at an extreme velocity.

\o/ <<< figure of ball in between 2 sloping walls.

can anyone find a way to solve this problem?

What value did you use for the restitution ? Can you give the code for the creation of the world / ball / wall ?

Creation of World

World world;
static final float GRAV = -0.98f;
static final int NB_ITERATION = 2000;

world = new World(new net.phys2d.math.Vector2f(0.0f, GRAV), NB_ITERATION);

Creation of Ball

Body objbody;
boolean _mv = true;
boolean _rt = true;
float _rd = 0.000001f;
float _re = 0.4f;

public PhysObject(DynamicShape ds, float mass) {
        objbody = new Body(ds, mass);
}
public void setupObj(float xPos, float yPos, float rotation) {
        objbody.setMoveable(_mv);
        objbody.setRotatable(_rt);
        objbody.setRotDamping(_rd);
        objbody.setPosition(xPos, yPos);
        objbody.setRotation(rotation);
        objbody.setRestitution(_re);
}
public void setRestitution(float re) {
        objbody.setRestitution(re);
}

PhysObject tempobj;
playerWidth = 0.09f;

tempobj = new PhysObject(new Circle(playerWidth), 5.0f);
tempobj.setupObj(-0.85f, 0.6f, 0.0f);
tempobj.setRestitution(1.75f);
list.add(tempobj);

Creation of 2 Walls

float _rd = 0.000001f;
float _re = 0.4f;

public PhysObject(DynamicShape ds, float mass) {
        objbody = new Body(ds, mass);
}
public void setupObj(float xPos, float yPos, float rotation, boolean moveable, boolean rotatable) {
        objbody.setMoveable(moveable);
        objbody.setRotatable(rotatable);
        objbody.setRotDamping(_rd);
        objbody.setPosition(xPos, yPos);
        objbody.setRotation(rotation);
        objbody.setRestitution(_re);
}

PhysObject tempobj;
net.phys2d.raw.shapes.Box b1 = new net.phys2d.raw.shapes.Box(0.8f, 0.03f);

tempobj = new PhysObject(b1, 5.0f);
tempobj.setupObj(-0.55f, 0.2f, -0.2f, false, false);
list.add(tempobj);

tempobj = new PhysObject(b1, 5.0f);
tempobj.setupObj(0.415f, 0.2f, 0.2f, false, false);
list.add(tempobj);

the problem occurs when a ball drops into a funnel-shaped wall… and is trapped between both sides of the wall. causing the restitution to make the ball bounce erratically.

i used 1.75f restitution for the ball and 0.4f restitution for the wall

i’ve posted my problem on youtube. please watch and help me with the problem please~

about the last part… the ball didnt disappear, but it flew away so fast the webcam could not capture it in time. -_-

Woaw 2000 iterations ;D (I use 4 or so :P)

I think the problem is the 1.75 for the restitution. If i do not make a mistake, restitution is the gain of cinetic energy after/before the collision. So with a restitution of 1, all the energy is keeped and the ball should keep the same velocity. With 0, it stop… With a value > 1, it will go faster.

So when the ball try to go behind the walls, there is a lot of short bounce in a short time. The ball get a lot of cinetic energy (speed). When Phys2D can’t see the collition with the 2000 iterations, the ball go away with a very high speed :o.

OMG… i changed my code to 4 iterations and the problem is solved!!!

:o :o :o :o :o :o :o :o :o :o :o :o :o :o :o :o :o :o :o :o :o :o

thanks for your help Bonbon-Chan. no one ever told me the number of iterations to use… :’(

wow it’s really fixed now… thanks alot~ :slight_smile: :slight_smile: :slight_smile:

Be sure to use restitution value less or equal to 1.0 too :wink: