0

I loaded a 3D model from asset Manager and add CharacterControl as a control. every thing was working correctly but when I tried to rotate the model it did`nt work.

private CharacterControl player;
private Spatial model;
public static final Quaternion YAW045   = new Quaternion().fromAngleAxis(FastMath.PI/4,   new Vector3f(0,1,0));

@Override
public void simpleInitApp() {

    // add bullet app sate to state manager
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);

this.addModel();
}

private void addModel(){
   model = assetManager.loadModel("Models/Oto/Oto.mesh.j3o");
   model.setLocalTranslation(new Vector3f(0,10,0));

    capsuleShape = new CapsuleCollisionShape(1f, 7.9f, 1);
    player = new CharacterControl(capsuleShape, 1f);
    bulletAppState.getPhysicsSpace().add(player);

   model.addControl(player);
   rootNode.attachChild(model);

   model.rotate(YAW045);
}

please help me.

RayanFar
  • 539
  • 11
  • 28
  • If I recall correctly (it's a while since I've done anything with controls) the player control is now controlling the rotation, position etc. You can't also manually move it because the control will move it straight back. I expect the character control will have a rotate method, although I could be wrong – Richard Tingle Apr 01 '16 at 22:45

1 Answers1

2

Richard is right. The CharacterControl class has a setViewDirection() method. You should really be switching to BetterCharacterControl though as it has better integration. I don't know why CharacterControl is not deprecated.

In general physics objects has a separate "life" as they live in the Bullet PhysicsSpace. For instance the other common physics control: RigidBodyControl class has a setPhysicsRotation(Quaternion rotation) method (just like it has a setPhysicsLocation() method).

More info is in the wiki (although it references CharacterControl) : Walking Character

reden
  • 968
  • 7
  • 14