简体   繁体   English

Box2D未检测到碰撞

[英]Box2D not detecting collision

I'm working on a game using the Box2D extension of the LibGdx library and everything is working like it should except for the collision detection. 我正在使用LibGdx库的Box2D扩展来开发游戏,除了碰撞检测之外,其他所有东西都应该像它应该的那样工作。

This is what it currently looks like: Image 这是当前的样子: 图片

The idea is the player (little circle) can jump in his bounds (gravity is set towards the center of the ground) to dodge the incoming obstacles, which are rotating around the ground. 这个想法是玩家(小圆圈)可以跳出边界(重力设置为朝向地面的中心)以躲避绕地面旋转的传入障碍物。 Once the obstacles reach the despawner, the ContactListener should call a method that will destroy the obstacle body. 一旦障碍物到达Despawner,ContactListener应调用将破坏障碍物主体的方法。

First of all, I have a few different bodies: 首先,我有几个不同的机构:

  • Player (Dynamic Body) 播放器(动态身体)
    The player is only affected by the gravity and some applied forces (no transforms) 播放器仅受重力和某些作用力的影响(无变换)
  • Ground (Kinematic Body) 地面(运动体)
    The ground only has a linearVelocity (that's why it's not a static body) 地面只有一个线速度(这就是为什么它不是静态物体的原因)
  • Obstacle (Kinematic Body) 障碍物(运动身体)
    The obstacle is moved using the setTransform(position, angle) method 使用setTransform(position,angle)方法移动障碍物
  • Despawner (Static Body) Despawner(静态身体)

I'm also using bit filters to manage the collisions (which I've triple checked and are not the source of the problem). 我还使用位过滤器来管理冲突(我已对其进行了三重检查,但这并不是问题的根源)。

The actual problem is that my ContactListener doesn't call the beginContact() method when the Obstacle Body is part of the collision, except if he's colliding with the Player Body. 实际的问题是,障碍物是碰撞的一部分时,除非他与Player Body碰撞,否则我的ContactListener不会调用beginContact()方法。 All the other bodies collide just fine with each other. 所有其他物体相互碰撞就很好。

Thank you for your help! 谢谢您的帮助!

from the manual here: 从这里的手册:

http://www.box2d.org/manual.html#_Toc258082973 http://www.box2d.org/manual.html#_Toc258082973

Kinematic bodies do not collide with other static or kinematic bodies. 运动体不会与其他静态或运动体碰撞。

you'll have to figure out a new way to trigger the despawner. 您将必须找出一种新方法来触发Despawner。 you won't be able to get collision between two kinetic or a kinetic and a static body type. 您将无法在两种动力学或动力学与静态身体类型之间发生碰撞。 maybe a body with a sensor fixture. 也许是带有传感器固定装置的身体。 or a Y position value. 或Y位置值。 or a dynamic body with gravity turned off. 或关闭重力的动态物体。

game looks cool, looking forward to it. 游戏看起来很酷,期待它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM