javaphysicsjmonkeyengine

how to rotate a spatial with physics control in JmonkeyEngine3?


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.


Solution

  • 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