问题
I have 2 bodies. After they collide second body disappears, and the first one must go on it's move in the in the same way as before the collision.
How it looks now:
1) I detect collision in contactListener::BeginContact(..) { };
2) Save the second body to delete , and the first to restore it's velocity and angle.
3)
-(void) update: (ccTime) dt {
int32 velocityIterations = 8;
int32 positionIterations = 1;
_world->Step(dt, velocityIterations, positionIterations);
...
world->DestroyBody(secondBody);
firstBody->SetLinearVelocity(linearVelocityBeforeTouching);
firstBody->SetTransform(firstBody->GetPosition(), angleBeforeTouching );
...
}
As a result the first body moves in the same direction, but it to rotate as after collision
回答1:
When the two bodies collide you could do contact->SetEnabled(false) in the PreSolve of the collision listener to cancel the default collision response.
来源:https://stackoverflow.com/questions/11061598/how-to-restore-b2body-state-after-collision