Hi Guys,
I'm new to Box2D and trying to learn and develop top-down game using it. I'm experiencing problem related to CCD and tunneling in Box2D.
To give you basic idea, I've two circle shape in my game, both are dynamic bodies, I'm trying to hit one with other by calculating drag & impulse but at least 4-5% time one body tunnels through the other body. Also it never penetrates the walls created with static bodies.
I tried setting bodydef.bullet = true;
world->SetContinuousPhysics(true);
Also tried to play with steps.. but no luck ? 😕
Is anybody experiencing something like this? Is there any way or workaround to fix this?
I'm new to Box2D and trying to learn and develop top-down game using it. I'm experiencing problem related to CCD and tunneling in Box2D.
To give you basic idea, I've two circle shape in my game, both are dynamic bodies, I'm trying to hit one with other by calculating drag & impulse but at least 4-5% time one body tunnels through the other body. Also it never penetrates the walls created with static bodies.
Code: Select all
CCSprite* body1Sprite = [CCSprite spriteWithFile:@"sprite1.png"];
[self addChild:body1Sprite];
ballBodyDef1.type = b2_dynamicBody;
ballBodyDef1.bullet = true;
ballBodyDef1.position.Set(PTM( 100 ), PTM (100 ));
ballBodyDef1.userData = body1Sprite;
ballBodyDef1.fixedRotation = true;
body2 = world->CreateBody(&ballBodyDef1);
b2CircleShape circle;
circle.m_radius = PTM (13.0 );
b2FixtureDef ballShapeDef1;
ballShapeDef1.shape = &circle;
ballShapeDef1.density = 30.0f;
ballShapeDef1.friction = 0.01f;
ballShapeDef1.restitution = 0.65f;
body1->CreateFixture(&ballShapeDef1);
body1->SetLinearDamping(0.95f);
CCSprite* body2Sprite = [CCSprite spriteWithFile:@"sprite2.png"];
[self addChild:body2Sprite];
ballBodyDef2.type = b2_dynamicBody;
ballBodyDef2.bullet = true;
ballBodyDef2.position.Set(PTM( 100 ), PTM (100 ));
ballBodyDef2.userData = body2Sprite;
ballBodyDef2.fixedRotation = true;
body2 = world->CreateBody(&ballBodyDef2);
b2CircleShape circle;
circle.m_radius = PTM (13.0 );
b2FixtureDef ballShapeDef2;
ballShapeDef2.shape = &circle;
ballShapeDef2.density = 30.0f;
ballShapeDef2.friction = 0.01f;
ballShapeDef2.restitution = 0.65f;
body2->CreateFixture(&ballShapeDef2);
body2->SetLinearDamping(0.95f);
I tried setting bodydef.bullet = true;
world->SetContinuousPhysics(true);
Also tried to play with steps.. but no luck ? 😕
Is anybody experiencing something like this? Is there any way or workaround to fix this?