How to rotate a model which is attached a charactrecontroll

CapsuleCollisionShape capsule = new CapsuleCollisionShape(1.65f, 0.000001f, 1);

character = new CharacterControl(capsule, 0.5f);
ghost = new GhostControl(capsule);
model.rotate(0, 4f, 0); // this rotation is not working :frowning:
model = (Node) assetManager.loadModel(ā€œModels/Ninja/Ninja.mesh.xmlā€);
model.addControl(ghost);
model.setLocalScale(new Vector3f(.085f, .08f, .073f));
model.addControl(character);
character.setPhysicsLocation(new Vector3f(0, 18, 0));
rootNode.attachChild(model);
getPhysicsSpace().add(character);
getPhysicsSpace().add(ghost);

// I get the walk directions by following approach
public void simpleUpdate(float tpf) {
Vector3f camDir = cam.getDirection().clone().multLocal(0.1f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.1f);
camDir.y = 0;
camLeft.y = 0;
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(camLeft);}
if (right) {
walkDirection.addLocal(camLeft.negate());}
if (up) {
walkDirection.addLocal(camDir); }
if (down) {
walkDirection.addLocal(camDir.negate()); }

    if (walkDirection.length() == 0) {
        if (!"Idle3".equals(channel.getAnimationName())) {
            channel.setAnim("Idle3", 1f);
        }
    } else {
        character.setViewDirection(walkDirection);

if (!ā€œWalkā€.equals(channel.getAnimationName())) {
channel.setAnim(ā€œWalkā€, 0.7f);

}

}
character.setWalkDirection(walkDirection);
}

Look at the rest of the code you copy-pasted the simpleUpdate method from.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

Hey Normen, I still learning this Jmonkey engine.Therefore I following the tutorials as well as examples within the docs.In here I ddnt mention that this my implementation.I just need a support…

You either set the viewDirection or attach the model to a node to rotate it separately from the character control influence.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

1 Like

CapsuleCollisionShape capsule = new CapsuleCollisionShape(1.65f, 0.000001f, 1);
//BoxCollisionShape capsule = new BoxCollisionShape(new Vector3f(0.5f, .5f, 4f));

    character = new CharacterControl(capsule, 10f);

    ghost = new GhostControl(capsule);

  
    Spatial ninja;
    ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    model.attachChild(ninja) ;                       // here   i attched the model to a node as u said. But it results java.lang.NullPointerException..:(
    model.addControl(ghost);
    model.setLocalScale(new Vector3f(.085f, .08f, .073f));
    model.rotate(0, 4f, 0);

Above code is resulting null pointer exception

Thnakz Normen you re a genius.I able to configure that problem as u said.Have a nice day :slight_smile: :wink: