I've got a bit of an issue, i got Chipmunk working nicely but if I set the mass of my bodies to a reasonable amount (so that items fall with gravity fast enough to look realistic) some of them will fall through the floor I have defined...
Any pointers would be hugely appreciated! Here's some code:
Code: Select all
cpInitChipmunk();
space = cpSpaceNew();
space->gravity = cpv(0, -200);
cpVect object_bounds[] = { cpv(0.0, 0.0), cpv(44.0, 0.0), cpv(44.0, -20.0), cpv(-44.0, -20.0) };
for (PhysicsSprite* physics_obj in physicsSprites) // I'm looping though 10 of these
{
cpBody *ballBody = cpBodyNew(20.0, 1000);
ballBody->p = cpv(physics_obj.x, physics_obj.y); // Positions are from x=628 to x=258 and all are at y=300
cpSpaceAddBody(space, ballBody);
cpShape* objectShape = cpPolyShapeNew(ballBody, 4, object_bounds, cpv(0.0, 0.0));
objectShape->e = 0.5; // Elasticity
objectShape->u = 0.8; // Friction
objectShape->data = physics_obj;
objectShape->collision_type = 1;
cpSpaceAddShape(space, objectShape);
}
// Create floor's body and set it's position
cpBody *altFloorBody = cpBodyNew(INFINITY, INFINITY);
altFloorBody->p = cpv(0.0, 10.0);
cpShape* altFloorShape = cpSegmentShapeNew(altFloorBody, cpv(0.0, 0.0), cpv(1124.0, 0.0), 0.0);
altFloorShape->e = 0.0; altFloorShape->u = 0.15; altFloorShape->collision_type = 0;
altFloorShape->data = floor;
cpSpaceAddStaticShape(space, altFloorShape);