box2d, destroing a b2_staticbody while colliding with a b2_dynamicbody leads to tunneling
I'm gonna make a function like "Doodle Jump": A ball(dynamicbody) jumps after collided with a platform(staticbody).
Here is how i implement this: 1. define own ContactListener:define a contact array which insert body while BeginContact, erase body while EndContact 2. [self scheduleupdate] to traverse contact array, if one body of contact is a platform(staticbody),destroy it.
The prob开发者_开发问答lem is the ball will not jump after collides with the platform and the platform destroies. The ball will just tunnel through the former staticbody.
Anyone can help?
Generally you'll want to use a b2_kinematicBody to simulate a platform, and set it's LinearVelocity to make it move.
You can make the platform move, given the illusion of a scrolling screen or jumping ball.
To emulate the bounce you can set the restitution to a value closer to 1.
To destroy the platform you can set a simple contactListener:
//in the end of update: method
if (bodyASprite.tag == BALL_TAG && bodyBSprite.tag == PLAT_TAG)
world->DestroyBody(bodyB);
else if (bodyASprite.tag == PLAT_TAG && bodyBSprite.tag == BALL_TAG)
world->DestroyBody(bodyA);
精彩评论