Box2D碰撞检测问题?

发布于 2024-12-29 13:12:12 字数 162 浏览 5 评论 0原文

我正在使用一个非常简单的 b2ContactListener。然而,当我的对象发生碰撞时,一次物理碰撞会有多个回调。有没有办法修改它或添加一些检查,以便物理上的一次碰撞只有一个回调?我已经为此苦苦挣扎了几个星期,但我似乎无法弄清楚:(

任何人都可以提供任何提示或建议吗?

谢谢!

I am using a very simple b2ContactListener. However when my objects collide, there are multiple callbacks for one collision physically. Is there any way to modify this or add some checks so that there will be only one callbacks for one collision physically? I have been struggling with this for weeks and I just can't seem to figure this out :(

Can anyone offer any tips or suggestions?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日久见人心 2025-01-05 13:12:13

为此,我在对象上使用了布尔标志。

当联系人被解雇时:

如果已设置标志=忽略
否则设置标志并将对象添加到 doSomethingNowWithThis 列表中。

这样,只有一个联系人设置标志,其余的都将被忽略。防止我过度去除。

可能有更好的方法,但这对我有用。

在 iOS 中使用 levelhelper 的示例。

   //I register a laser to hit the roof
   [lh registerBeginOrEndCollisionCallbackBetweenTagA:PLAYERFIRE 
                                               andTagB:ROOF 
                                            idListener:self 
                                           selListener:@selector(flagPartAToDie:)];

    //Then it calls this
   -(void)flagPartAToDie:(LHContactInfo*)contact {
    MyUserData* myud;
    LHSprite* part = [contact spriteA];
    myud = (MyUserData*) part.userData;
    if (!myud.DeleteMe) {
        myud.DeleteMe = YES;
        [deadParts addObject: part];            
    }    
 }

I use a bool flag on my objects for this.

When a contact is fired:

if the flag is set already = just ignore
else set the flag and add the object to the doSomethingNowWithThis list.

This way only one contact sets the flag, and the rest are ignored. Prevents me from over-removing.

There might be a better way, but this works for me.

Example using levelhelper in iOS.

   //I register a laser to hit the roof
   [lh registerBeginOrEndCollisionCallbackBetweenTagA:PLAYERFIRE 
                                               andTagB:ROOF 
                                            idListener:self 
                                           selListener:@selector(flagPartAToDie:)];

    //Then it calls this
   -(void)flagPartAToDie:(LHContactInfo*)contact {
    MyUserData* myud;
    LHSprite* part = [contact spriteA];
    myud = (MyUserData*) part.userData;
    if (!myud.DeleteMe) {
        myud.DeleteMe = YES;
        [deadParts addObject: part];            
    }    
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文