【问题标题】:BetterCharacterControl not applying RigidBody at the right PositionBetterCharacterControl 没有在正确的位置应用 RigidBody
【发布时间】:2014-05-15 11:51:44
【问题描述】:

所以我是 JME3 的新手,我在理解 BetterCharacterControl 时遇到了一些问题。

当我尝试将 BetterCharacterControl 应用于框时,它总是从框的上部而不是中心“扩展”。 (一张图更能说明问题:)

我找不到任何函数来更改它应用的位置,我已经尝试创建一个子类,在其中我将 RigidBody 直接更改为 BoxCollisionShape 但这似乎以某种方式搞砸了 isOnGround 方法。另外,如果我以后想使用斜坡,那么胶囊形状会很好。

Box box2 = new Box(10, 15, 10);
player = new Geometry("Player", box2);
player.setLocalTranslation(new Vector3f(0, 20, 0));
Material mat = new Material(assetManager, 
            "Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Ambient", ColorRGBA.Blue);
mat.setColor("Diffuse", ColorRGBA.Blue);
player.setMaterial(mat);

playerC = new BetterCharacterControl(12, 30, 0);
playerC.setJumpForce(new Vector3f(0, 700, 0));
player.addControl(playerC);

rootNode.attachChild(player);

bulletAppState.getPhysicsSpace().add(playerC);

另一方面,我似乎必须为跳跃力应用一个巨大的矢量才能让它做任何事情(我没有改变任何重力值)

很高兴得到任何帮助

【问题讨论】:

  • 你觉得反其道而行之;使图形适合物理。我只是使用一个节点来相对于播放器移动 box2(或者只是为盒子设置本地翻译)

标签: java jmonkeyengine jbullet


【解决方案1】:

我遇到了同样的问题。我解决它的方式并不常见。我编写了一个类并继承了 BetterCharacterControl 覆盖 getShape() 方法,如下所示:

protected CollisionShape getShape() {
    //TODO: cleanup size mess..
    CapsuleCollisionShape capsuleCollisionShape = new CapsuleCollisionShape(getFinalRadius(), (getFinalHeight() - (2 * getFinalRadius())));
    CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape();
    //Vector3f addLocation = new Vector3f(0, (getFinalHeight() / 2.0f), 0); REMOVED LINE
    Vector3f addLocation = new Vector3f(0, 0, 0); //NEW LINE
    compoundCollisionShape.addChildShape(capsuleCollisionShape, addLocation);
    return compoundCollisionShape;
}

这是有效的,因为原始代码是以这样一种方式创建的复合代码,以便子节点偏移值:(getFinalHeight () / 2.0f)。新行添加不实现此移位,将对象留在框集的中心位置。但是,这种解决问题的方法,在最终对象中实际使用复合网格时会产生问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多