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