[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - Linking two bodies.

Linking two bodies.

Official forum for the .

Linking two bodies.

Postby zhaoling_0309 » Sun Apr 01, 2012 10:26 pm

Hi, everyone.

I am going to make two bodies linked to each other,so moving together, but rotating independently.
Here are some codes that I have tried to implement these bodies.

mainSprite = [CCSprite spriteWithSpriteFrame:[frameCache spriteFrameByName:@"character.png"]];
mainSprite.scale = 0.6f;
[parentLayer addChild:mainSprite z:Z_CHARACTER];

basketSprite = [CCSprite spriteWithSpriteFrame:[frameCache spriteFrameByName:@"basket.png"]];
[parentLayer addChild:basketSprite z:Z_CHARACTER];

// Character Body
body = cpBodyNew(10000.0f, INFINITY);
bodyShape = cpCircleShapeNew(body, 45.0f, cpvzero);
cpSpaceAddBody(space, body);
cpSpaceAddShape(space, bodyShape);
cpShapeSetCollisionType(bodyShape, CHARACTER_COLLISION_GROUP);
cpShapeSetFriction(bodyShape, 0.2f);
cpBodySetPos(body, _initPos);
cpShapeSetGroup(bodyShape, CHARACTER_GROUP);
cpBodySetUserData(body, mainSprite);

// Basket
basketBody = cpBodyNew(10.0f, cpMomentForBox(100, 150, 15));
cpSpaceAddBody(space, basketBody);
cpVect verts1[] = { ccp(0, 30), ccp(10, 30), ccp(20, 0), ccp(10, 0) };
cpVect verts2[] = { ccp(0, 10), ccp(100, 10), ccp(100, 0), ccp(0, 0) };
cpVect verts3[] = { ccp(90, 30), ccp(100, 30), ccp(90, 0), ccp(80, 0) };
cpShape *testShape1 = cpPolyShapeNew(body, 4, verts1, ccp(-25, 50));
cpShape *testShape2 = cpPolyShapeNew(body, 4, verts2, ccp(-25, 50));
cpShape *testShape3 = cpPolyShapeNew(body, 4, verts3, ccp(-25, 50));
cpSpaceAddShape(space, testShape1);
cpSpaceAddShape(space, testShape2);
cpSpaceAddShape(space, testShape3);
cpShapeSetFriction(testShape1, 100000.0f);
cpShapeSetFriction(testShape2, 100000.0f);
cpShapeSetFriction(testShape3, 100000.0f);
cpShapeSetGroup(testShape1, CHARACTER_GROUP);
cpShapeSetGroup(testShape2, CHARACTER_GROUP);
cpShapeSetGroup(testShape3, CHARACTER_GROUP);
cpShapeSetCollisionType(testShape1, CHARACTER_BASKET_COLLISION_TYPE);
cpShapeSetCollisionType(testShape2, CHARACTER_BASKET_COLLISION_TYPE);
cpShapeSetCollisionType(testShape3, CHARACTER_BASKET_COLLISION_TYPE);
cpBodySetUserData(basketBody, basketSprite);

But i have couple of troubles.
1st, Basket sprite and basket body don't link up with each other.
2nd, Controlling angle velocity don't work on basket body.

Have you any idea about this?

Thanks.
zhaoling_0309
 
Posts: 2
Joined: Sun Apr 01, 2012 8:00 pm

Re: Linking two bodies.

Postby slembcke » Mon Apr 02, 2012 9:54 am

Did you add a joint anywhere? You'll need a pivot joint if you want them to move together.

What do you mean you can't control the angular velocity of the basket?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Linking two bodies.

Postby zhaoling_0309 » Mon Apr 02, 2012 10:02 am

I mean I can't control the rotation of basket body with cpBodySetAngVel.

And thanks for your reply.
I will try pivot joint.

Regards.
zhaoling_0309
 
Posts: 2
Joined: Sun Apr 01, 2012 8:00 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests