BetterCharacterControl

BetterCharacterControl

我想从在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(),只有一个受保护的字段称为“location”。

任何输入,不胜感激。

最佳答案

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

BetterCharacterControl不是Spatial,因此很难跟随摄像机。相反,您应该让摄像机遵循BCC附加到的空间。

08-03 19:46