I will be using chimpunk for a university project and I am now playing a little bit with the library. It seems pretty cool for now.
Now, my problem
I have a static body with 4 static shapes (for the 4 walls around the window), in that box I put a lot of moving objects (balls). The balls bounce of each other very well, but they don't of walls, when they touch the wall, they stick to it.
I tried a lot of elasticity and friction combos, but neither did what I want.
Here's some relevant code :
This is the function that is called in order to add another ball in the world:
Code: Select all
cpFloat moment = cpMomentForPoly(mass, 4, verts, cpvzero);
body = cpBodyNew(mass, moment);
body->p = position;
body->v = velocity;
cpSpaceAddBody(space, body);
shape = cpCircleShapeNew(body, 10.0f, cpvzero);
shape->e = 0.8f;
shape->u = 1.5f;
shape->collision_type = 0;
cpSpaceAddShape(space, shape);
Code: Select all
cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(0,600), 0.0f);
shape->e = 0.0f; shape->u = 1.5f;
shape->collision_type = 0;
cpSpaceAddStaticShape(space, shape);
//shape = cpSegmentShapeNew(staticBody, cpv(0,600), cpv(800,600), 0.0f);
// This was a test to be sure that it isn't because of the Segment shape.
shape = cpPolyShapeNew(staticBody, 4, ground, cpvzero);
shape->e = 0.6f; shape->u = 1.5f;
shape->collision_type = 0;
cpSpaceAddStaticShape(space, shape);
shape = cpSegmentShapeNew(staticBody, cpv(800,600), cpv(800,0), 0.0f);
shape->e = 0.0f; shape->u = 1.0f;
shape->collision_type = 0;
cpSpaceAddStaticShape(space, shape);
shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(800,0), 0.0f);
shape->e = 0.0f; shape->u = 1.0f;
shape->collision_type = 0;
cpSpaceAddStaticShape(space, shape);
As you can see, I am stealing a lot of code from the demos and tutorials, gotta learn somehow
So, can anyone help me get those balls start to bounce like a real ball should ?
Thanks.