Block Topple

Official forum for the Chipmunk2D Physics Library.
Post Reply
rdominelli
Posts: 3
Joined: Wed Aug 12, 2009 10:56 am
Location: Directly behind you
Contact:

Block Topple

Post by rdominelli »

Is there a spectial trick to enable rotational "topple" logic on cpPolyShape?

Code: Select all

	cpVect verts[] = {
		cpv(-20,-40),
		cpv(-20, 40),
		cpv(20, 40),
		cpv(20,-40),
	};
	cpBody* brickBody1 = cpBodyNew(150, cpMomentForPoly(150, 4, verts, cpvzero));
	
	brickBody1->p = cpv(260,100);
	cpSpaceAddBody(space, brickBody1);

	cpShape * brickShape = cpPolyShapeNew(brickBody1, 4, verts, cpvzero);
	brickShape->e = .2;
	brickShape->u = .4;
	brickShape->collision_type = 2;
	brickShape->data = brickSprite;
	cpSpaceAddShape(space, brickShape);
Is the setup for the 1 of 2 rectangular brick objects which are stacked one on another. The bricks are stuck by bouncing balls, and even if there is merely a 1 pixel overlap between the two, the top brick will not topple over.

Is there another param I should be setting for this? i tried varying the mass and inertia but they don't seem to be doing anything.

Rich
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Block Topple

Post by slembcke »

I'm not sure what you mean by "Topple" other than things should fall over. There is no magic to that as long as the moment of inertia is set correctly, which it is. I'm also not sure what you mean when you say they are stuck together with balls. They are sticking together instead of falling over?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
rdominelli
Posts: 3
Joined: Wed Aug 12, 2009 10:56 am
Location: Directly behind you
Contact:

Re: Block Topple

Post by rdominelli »

Code: Select all

void updateShape(void* ptr, void* unused){
	cpShape* shape = (cpShape*)ptr;
	Sprite* sprite = shape->data;
	if(sprite){
		cpBody* body = shape->body;
		[sprite setPosition:cpv(body->p.x, body->p.y)];
	
	}
}
Ah Watching the motions carefully I think I see my problem. My update Shape does nothing to rotate the Cocos 2d Sprite so even if the chipmunk shape is rotated I am not taking it into account.

Any good examples for this?

Rich
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Block Topple

Post by slembcke »

I've never actually used Cocos2D, but I'm sure there are a few threads here about that, and a ton at the Cocos2D forums I would suspect.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
patrickC
Posts: 7
Joined: Sat May 02, 2009 10:55 am
Contact:

Re: Block Topple

Post by patrickC »

Code: Select all

[sprite setRotation:-(body->a)*180/M_PI];
rdominelli
Posts: 3
Joined: Wed Aug 12, 2009 10:56 am
Location: Directly behind you
Contact:

Re: Block Topple

Post by rdominelli »

You Rock....
That worked perfectly.

Thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests