如何在JMonkeyEngine3中访问BetterCharacterControl对象的Vector3f位置?

4

我想要从已弃用的“CharacterControl”转向“BetterCharacterControl”,用于我在JMonkeyEngine3中制作的3D游戏。以下是我已经编写的初始化它们的代码:

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() 这样的方法,只有一个叫做“location”的受保护字段。
非常感谢您的关注。
1个回答

2

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

BetterCharacterControl不是Spatial,因此让相机跟随它很困难。您应该让相机跟随BCC所附加到的空间物体。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接