AndEngine 和 box2d 碰撞过滤

发布于 2025-01-07 01:46:04 字数 153 浏览 0 评论 0原文

我遇到两个物体(一动态一静态)之间碰撞的问题。假设我有墙和球,我设置了过滤器,允许球穿过墙。只要我创建主体在墙体外的精灵,它就可以很好地工作。当我在与墙壁相同的位置创建球然后球被卡住或弹跳或做奇怪的事情时,就会出现问题。我相信,如果有碰撞过滤器,在哪里创建主体应该没有关系。有人有类似问题吗?

I have a problem with collision between 2 bodies(one dynamic and one static). Lets say that I have wall and ball, I set filter which allows the ball to pass through the wall. It works good as long as I create sprite with body outside the wall body. The problem appears when I create ball at the same position as wall then the ball gets stuck or bounce or does weird things. I believe that it shouldn't has matter where I create the body if there is collision filter. Had anyone similar problem ?

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

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

发布评论

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

评论(2

梦里人 2025-01-14 01:46:04

我仍然不知道为什么会出现问题,但我知道如果我创建 boxBody 和 CircleBody 就会发生这种情况。我使用 PolygonBody 而不是 BoxBody 解决了这个问题。这是我的代码,它从多边形体创建盒子。

float a = this.getWidthScaled()*0.5f/32.0f;
float b = this.getHeightScaled()*0.5f/32.0f;
Vector2[] v = {new Vector2(-a,-b), 
               new Vector2(a,-b),
               new Vector2(a,b),
               new Vector2(-a,b)};
body = PhysicsFactory.createPolygonBody(pWorld, this, v, BodyType.DynamicBody, mFixtureDef);

I still don't know why the problem appears but I know that it happens if I create boxBody and circleBody. I solved this problem using polygonBody instead of boxBody. Here is my code which create box from polygon body.

float a = this.getWidthScaled()*0.5f/32.0f;
float b = this.getHeightScaled()*0.5f/32.0f;
Vector2[] v = {new Vector2(-a,-b), 
               new Vector2(a,-b),
               new Vector2(a,b),
               new Vector2(-a,b)};
body = PhysicsFactory.createPolygonBody(pWorld, this, v, BodyType.DynamicBody, mFixtureDef);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文