Cocos2d box2d: different mass, but the body falls at the same time

I created 2 body2d body with cocos2d sprite .... they have different masses and they fall from the same place in the world. but they fall at the same time. my idea is that a lighter body should fall later than a heavy ... but they did not.

for (int k=1;k<=2; k++) { int idx = (CCRANDOM_0_1() > .5 ? 0:1); int idy = (CCRANDOM_0_1() > .5 ? 0:1); CCSprite *sprite = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(32 * idx,32 * idy,32,32)]; [batch addChild:sprite]; sprite.position = ccp( p.x+(32*k), py); b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(( p.x+(32*k))/PTM_RATIO, py/PTM_RATIO); bodyDef.userData = sprite; b2Body *body = world->CreateBody(&bodyDef); b2PolygonShape dynamicBox; dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box b2FixtureDef fixtureDef; fixtureDef.shape = &dynamicBox; fixtureDef.density = 1.0f/k; fixtureDef.friction = 0.3f; body->CreateFixture(&fixtureDef); NSLog(@"%f",body->GetMass()); } 
+4
source share
2 answers

You can set another damping of these bodies.

Experiment with different values. 0 means no damping, but the maximum value is unlimited, so be careful.

0
source

All Articles