【问题标题】:How can I access the Vector3f location of a BetterCharacterControl object in JMonkeyEngine3?如何访问 JMonkeyEngine3 中 BetterCharacterControl 对象的 Vector3f 位置?
【发布时间】:2015-12-07 10:38:21
【问题描述】:

对于我在 JMonkeyEngine3 中搞乱的 3D 游戏,我想从已弃用的“CharacterControl”转移到“BetterCharacterControl”这是我迄今为止启动它们的代码:

public void initPlayer(){
  // We set up collision detection for the player by creating
  // a capsule collision shape and a CharacterControl.
  CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
  player = new CharacterControl(capsuleShape, 0.05f);
  player.setJumpSpeed(20);
  player.setFallSpeed(30);
  player.setGravity(30);
  player.setPhysicsLocation(new Vector3f(-10, 10, 10));
  bulletAppState.getPhysicsSpace().add(player);

}

public void initBetterPlayer(){
  CapsuleCollisionShape betterCapsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
  betterPlayer = new BetterCharacterControl(2f,6f,1f);
  // set basic physical properties:
  betterPlayer.setJumpForce(new Vector3f(0,5f,0)); 
  betterPlayer.setGravity(new Vector3f(0, 1f ,0));
  betterPlayer.warp(new Vector3f(-10, 10, 10));
  bulletAppState.getPhysicsSpace().add(betterPlayer);

}

在 initBetterPlayer() 中,我也无法将 CapsuleCollisionShape 链接到 BetterPlayer。

这里是我在 simpleUpdate() 方法中使用位置的地方:

player.setWalkDirection(walkDirection);
cam.setLocation(player.getPhysicsLocation());

问题是 BetterCharacterControl 似乎没有像 getPhysicsLocation() 这样的方法,只有一个名为“位置”的受保护字段。

非常感谢任何输入。

【问题讨论】:

    标签: java jmonkeyengine


    【解决方案1】:

    如果您查看 BetterCharacterControl 类及其 getShape() 方法,您会发现它创建了一个 CollisionShape 并返回(它不存储它)。通过覆盖类中的方法,您应该能够提供自己的形状(除非您发现可以使用它的值来代替。它也使用 CapsuleCollisionShape)。

    BetterCharacterControl 不是 Spatial,因此很难让相机跟随它。相反,您应该让相机跟随密件抄送附加到的空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多