4

I'm wanting to move away from the deprecated "CharacterControl" to the "BetterCharacterControl" for the 3D game I'm messing with in JMonkeyEngine3 Here is the code I have so far for initiating them:

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);

}

In the initBetterPlayer() i'm also having trouble linking the CapsuleCollisionShape to the betterPlayer.

And here is where I use the location in the simpleUpdate() method:

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

The problem is there is no method like getPhysicsLocation() for BetterCharacterControl it seems, only a protected field called "location".

Any input is greatly appreciated.

danizmax
  • 2,446
  • 2
  • 32
  • 41
Tparker12
  • 41
  • 4

1 Answers1

2

If you look at the BetterCharacterControl class and its getShape() method you can see that it creates a CollisionShape which it returns (it doesn't store it). By overriding the method in your class you should be able to supply your own shape (unless you find out that you can work with its values instead. It's also using a CapsuleCollisionShape).

The BetterCharacterControl is not a Spatial, so having a camera follow it is difficult. You should instead have the camera follow the spatial the BCC is attached to.

reden
  • 968
  • 7
  • 14