"Quicksand"-like issue (not intentional)

Official forum for the Chipmunk2D Physics Library.
Post Reply
jzlosman
Posts: 2
Joined: Sat Jun 19, 2010 11:58 am
Contact:

"Quicksand"-like issue (not intentional)

Post by jzlosman »

First off, Slembcke, great engine, its a big help.

Alright, so I run through a nested for loop and create a grid of block objects (6 rows of 7 blocks). I then create a ball and for now I just drop it from the top of the screen. The physics and everything is working, the ball bounces around and destroys certain blocks on impact. But, when the ball comes to rest on top of a block, it then begins to slowly sink through the block.

I've noticed a direct relationship between the difference in the two objects' masses - the greater the difference the slower the sinking. However, I don't think objects should just be passing through others based on mass - but I could be wrong.

Here is bit of code for the blocks - (I had the block at about 20.0f but had to bring it to 900.0f or more to slow down the sinking)

Code: Select all

cpBody *body = cpBodyNew(900.0f, INFINITY);
	body->p = CGPointMake(x, y);
	cpShape *shape = cpPolyShapeNew(body, num, verts, CGPointZero);
	shape->e = 0.5f; shape->u = 0.25f;
	shape->data = sprite;
	shape->group = 1;
	shape->collision_type =type;
	cpSpaceAddShape(space, shape);
And here is the ball code -

Code: Select all

cpBody *ballBody = cpBodyNew(6.0f,cpMomentForCircle(3.0f, 9.5, 9.5, CGPointZero));
	ballBody->p = point;
	cpSpaceAddBody(space, ballBody);
	cpShape* shape = cpCircleShapeNew(ballBody, 9.5, CGPointZero);
	shape->e = .94f; shape->u = 0.08f;
	shape->data = ballSprite;
	shape->collision_type = kNone;
	cpSpaceAddShape(space, shape);
Also, note that I've tried INFINITY for momentum too, that has no affect.

Any help would be appreciated, as I couldn't find any similar posts on the board - (Anyone looking to make a quicksand effect, take the code above :D )
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: "Quicksand"-like issue (not intentional)

Post by slembcke »

If the blocks are supposed to be static, the mass must be infinity. Otherwise the collisions will still transfer velocity to the blocks. If the blocks aren't added to the space, their positions won't change so it will look like they are not moving, but their velocity won't be zero in the collision calculations.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jzlosman
Posts: 2
Joined: Sat Jun 19, 2010 11:58 am
Contact:

Re: "Quicksand"-like issue (not intentional)

Post by jzlosman »

So I set the mass to INFINITY and I crash like crazy now -

I crash when I add the body to the space, and when I don't
I crash when I add the shape as Static and when I don't

As a StaticShape can I still add a collisionType to it and do collisions based on that, or are there any other properties I have to remove in order to treat it as a StaticShape?

Code: Select all

cpBody *body = cpBodyNew(INFINITY, INFINITY);
	body->p = CGPointMake(x, y);
	cpSpaceAddBody(space, body);
	cpShape *shape = cpPolyShapeNew(body, num, verts, CGPointZero);
	switch(type){
		case kIce:
			shape->e = 0.2f; shape->u = 0.02f;
			break;
		default:
			shape->e = 0.5f; shape->u = 0.25f;
			break;
	}
	shape->data = sprite;
	shape->group = 1;
	shape->collision_type =type;
	cpSpaceAddStaticShape(space, shape);
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests