How to restore b2Body state after collision?

半腔热情 提交于 2019-12-25 04:06:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!