碰撞后如何恢复b2Body状态? [英] How to restore b2Body state after collision?

查看:96
本文介绍了碰撞后如何恢复b2Body状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个机构。 碰撞后,第二个身体消失,并且第一个必须以与碰撞前相同的方式继续前进

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.

现在的样子:

1)我在contactListener :: BeginContact中检测到碰撞(..){};

1) I detect collision in contactListener::BeginContact(..) { };

2)保存第二个要删除的物体,第一个恢复其速度和角度。

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 );
...
}

因此,第一个正文沿相同的方向移动,但是它像碰撞后一样旋转

推荐答案

当两个物体碰撞时,您可以$ p $ b,请使用碰撞侦听器的PreSolve中的contact-> SetEnabled(false)取消默认的碰撞响应。

When the two bodies collide you could do contact->SetEnabled(false) in the PreSolve of the collision listener to cancel the default collision response.

这篇关于碰撞后如何恢复b2Body状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆