1

所以我是 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);

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

我很高兴有任何帮助

4

1 回答 1

0

我有同样的问题。我解决它的方式并不常见。我编写了一个类并从 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)。新行添加不实现此移位,将对象留在框集的中心位置。然而,这种解决问题的方法,在最终对象中实际使用复合网格时会产生问题。

于 2014-11-10T02:00:53.740 回答