Objects sometimes falling through floor

Official forum for the Chipmunk2D Physics Library.
Post Reply
Workshed
Posts: 2
Joined: Mon Nov 08, 2010 5:24 am
Contact:

Objects sometimes falling through floor

Post by Workshed »

Hi guys,

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);  
gerrit
Posts: 6
Joined: Wed Feb 24, 2010 5:53 am
Contact:

Re: Objects sometimes falling through floor

Post by gerrit »

I just tackled this by bumping up the iterations and using a polygon shape with some depth to it as my ground (instead of a segment shape like all of the examples use).
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Objects sometimes falling through floor

Post by slembcke »

Chipmunk does not support swept collisions. This means that if your objects are small, moving fast, and you are using a large timestep, they may be able to pass through each other without generating collisions.

The solution is to do the opposite, make your objects larger or your ground thicker, cap their velocity so they don't move as fast, and/or use a smaller timestep.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Workshed
Posts: 2
Joined: Mon Nov 08, 2010 5:24 am
Contact:

Re: Objects sometimes falling through floor

Post by Workshed »

Thanks for that guys, I'll have a play with it :)
It's reassuring to know that i've not done something stupid in the setup :D
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests