How to rotate the robot ,when click the "S" key/Move Back Key

package jme3test.helloworld;

import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.ZipLocator;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.input.ChaseCamera;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Matrix3f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.CameraNode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.CameraControl.ControlDirection;
import com.jme3.scene.shape.Box;
import javax.vecmath.Vector3d;

/**

  • A walking physical character followed by a 3rd person camera. (No animation.)

  • @author normenhansen, zathras
    */
    public class TestPhysicsCharacter2 extends SimpleApplication implements ActionListener, AnimEventListener {

    private AnimChannel channel;
    private AnimControl control;
    private Spatial sceneModel;
    private RigidBodyControl landscape;
    private BulletAppState bulletAppState;
    // private CharacterControl physicsCharacter;
    // private Node characterNode;
    private CharacterControl character;
    private Node model;
    private CameraNode camNode;
    ChaseCamera chaseCam;
    boolean rotate = false;
    private Vector3f walkDirection = new Vector3f(0, 0, 0);
    private Vector3f viewDirection = new Vector3f(0, 0, 0);
    boolean leftStrafe = false, rightStrafe = false, forward = false, backward = false,
    leftRotate = false, rightRotate = false;

    public static void main(String[] args) {
    TestPhysicsCharacter2 app = new TestPhysicsCharacter2();
    app.start();
    }

    private void setupKeys() {
    inputManager.addMapping(“Strafe Left”,
    new KeyTrigger(KeyInput.KEY_Q),
    new KeyTrigger(KeyInput.KEY_Z));
    inputManager.addMapping(“Strafe Right”,
    new KeyTrigger(KeyInput.KEY_E),
    new KeyTrigger(KeyInput.KEY_X));
    inputManager.addMapping(“Rotate Left”,
    new KeyTrigger(KeyInput.KEY_A),
    new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping(“Rotate Right”,
    new KeyTrigger(KeyInput.KEY_D),
    new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping(“Walk Forward”,
    new KeyTrigger(KeyInput.KEY_W),
    new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping(“Walk Backward”,
    new KeyTrigger(KeyInput.KEY_S),
    new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping(“Jump”,
    new KeyTrigger(KeyInput.KEY_SPACE),
    new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping(“pull”, new KeyTrigger(keyInput.KEY_P));
    inputManager.addMapping(“push”, new KeyTrigger(keyInput.KEY_O));
    inputManager.addMapping(“Dodge”, new KeyTrigger(keyInput.KEY_I));
    inputManager.addMapping(“Shoot”,
    new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(this, “Strafe Left”, “Strafe Right”);
    inputManager.addListener(this, “Rotate Left”, “Rotate Right”);
    inputManager.addListener(this, “Walk Forward”, “Walk Backward”);
    inputManager.addListener(this, “Jump”, “Shoot”);
    // inputManager.addListener(this, “pull”);
    // inputManager.addListener(this, “push”);
    // inputManager.addListener(this, “Dodge”);

     inputManager.addListener(actionListener, new String[]{"Walk Backward","Walk Forward","pull","push","Dodge"});
    

    }
    private ActionListener actionListener = new ActionListener() {
    public void onAction(String name, boolean keyPressed, float tpf) {
    if (name.equals(“Walk Forward”) && keyPressed) {
    if (!channel.getAnimationName().equals(“Walk”)) {
    channel.setAnim(“Walk”, 0.50f);

       channel.setLoopMode(LoopMode.Loop);
     }
    

    }
    if (name.equals(“Walk Backward”) && keyPressed) {
    // character.setPhysicsLocation(new Vector3f(0, 0, 30));
    // character.setPhysicsLocation(new Vector3f(6, character.getPhysicsLocation().y, character.getPhysicsLocation().z));
    //character.setViewDirection(character.getViewDirection().add(50, tpf, tpf));
    if (!channel.getAnimationName().equals(“Walk”)) {

       channel.setAnim("Walk", 0.50f);
      
       channel.setLoopMode(LoopMode.Loop);
     }
    

    }

    if (name.equals("pull") && !keyPressed) {
     if (!channel.getAnimationName().equals("pull")) {
       channel.setAnim("pull", 0.50f);
       channel.setLoopMode(LoopMode.Loop);
     }
    

    }

     if (name.equals("push") && !keyPressed) {
     if (!channel.getAnimationName().equals("push")) {
       channel.setAnim("push", 0.50f);
       channel.setLoopMode(LoopMode.Loop);
     }
    

    }
    if (name.equals(“Dodge”) && !keyPressed) {
    if (!channel.getAnimationName().equals(“Dodge”)) {
    channel.setAnim(“Dodge”, 0.50f);
    channel.setLoopMode(LoopMode.Loop);
    }
    }

    }
    };

    @Override
    public void simpleInitApp() {
    // activate physics
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);

     // init a physical test scene
     //PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace());
     setupKeys();
     viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
     //flyCam.setMoveSpeed(100);
     //setUpKeys();
     setUpLight();
    
     // We load the scene from the zip file and adjust its size.
     assetManager.registerLocator("town.zip", ZipLocator.class);
     sceneModel = assetManager.loadModel("main.scene");
     sceneModel.setLocalScale(3f);
     CollisionShape sceneShape =
             CollisionShapeFactory.createMeshShape((Node) sceneModel);
     landscape = new RigidBodyControl(sceneShape, 0);
     sceneModel.addControl(landscape);
     rootNode.attachChild(sceneModel);
     getPhysicsSpace().add(landscape);
    
     CapsuleCollisionShape capsule = new CapsuleCollisionShape(6f, 4f, 1);
     character = new CharacterControl(capsule, 0.5f);
     model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
     model.setLocalScale(1.5f);
       control = model.getControl(AnimControl.class);
    

    control.addListener(this);
    channel = control.createChannel();
    channel.setAnim(“stand”);
    model.addControl(character);
    character.setPhysicsLocation(new Vector3f(0, 5, 0));
    character.setJumpSpeed(30);
    character.setGravity(130);
    rootNode.attachChild(model);
    getPhysicsSpace().add(character);

     // set forward camera node that follows the character
    
     camNode = new CameraNode("CamNode", cam);
     camNode.setControlDir(ControlDirection.SpatialToCamera);
     camNode.setLocalTranslation(new Vector3f(0, 18, -27));
     camNode.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y);
    
     model.attachChild(camNode);
    
     //disable the default 1st-person flyCam (don't forget this!!)
     flyCam.setEnabled(false);
    
     chaseCam = new ChaseCamera(cam, model, inputManager);
    
     AmbientLight al = new AmbientLight();
     al.setColor(ColorRGBA.White.mult(1.3f));
     rootNode.addLight(al);
    
     // bulletAppState.getPhysicsSpace().add(modelBodyControl);
    

// Box box = new Box(new Vector3f(0, -4, -5), 15, .2f, 15);
// Spatial floor = new Geometry(“the Floor”, box);
// Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
// mat1.setColor(“Color”, ColorRGBA.Gray);
// floor.setMaterial(mat1);
// CollisionShape floormesh = CollisionShapeFactory.createMeshShape(floor);
// RigidBodyControl landscape1 = new RigidBodyControl(floormesh, 0);
// floor.addControl(landscape1);
// rootNode.attachChild(floor);
// getPhysicsSpace().add(landscape1);

}

public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

// if (animName.equals(“Walk”)) {
// channel.setAnim(“stand”, 0.50f);
// channel.setLoopMode(LoopMode.DontLoop);
// channel.setSpeed(1f);
// }
if (animName.equals(“pull”)) {
channel.setAnim(“stand”, 0.50f);
channel.setLoopMode(LoopMode.DontLoop);
channel.setSpeed(1f);
}

    if (animName.equals("push")) {
        channel.setAnim("stand", 0.50f);
        channel.setLoopMode(LoopMode.DontLoop);
        channel.setSpeed(1f);
    }
    if (animName.equals("Dodge")) {
        channel.setAnim("stand", 0.50f);
        channel.setLoopMode(LoopMode.DontLoop);
        channel.setSpeed(1f);
    }
}

public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
    // unused
}

@Override
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 (leftStrafe) {
        walkDirection.addLocal(camLeft);
    } else if (rightStrafe) {
        walkDirection.addLocal(camLeft.negate());
    } else if (leftRotate) {
        viewDirection.addLocal(camLeft.mult(0.02f));
    } else if (rightRotate) {
        viewDirection.addLocal(camLeft.mult(0.02f).negate());
    } else if (forward) {
        walkDirection.addLocal(camDir);
    } else if (backward) {
        walkDirection.addLocal(camDir.negate());
    }

    character.setWalkDirection(walkDirection);
    character.setViewDirection(viewDirection);

}

public void onAction(String binding, boolean value, float tpf) {
    if (binding.equals("Strafe Left")) {
        if (value) {
            leftStrafe = true;
        } else {
            leftStrafe = false;
        }
    } else if (binding.equals("Strafe Right")) {
        if (value) {
            rightStrafe = true;
        } else {
            rightStrafe = false;
        }
    } else if (binding.equals("Rotate Left")) {
        if (value) {
            leftRotate = true;
        } else {
            leftRotate = false;
        }
    } else if (binding.equals("Rotate Right")) {
        if (value) {
            rightRotate = true;
        } else {
            rightRotate = false;
        }
    } else if (binding.equals("Walk Forward")) {
        if (value) {
            forward = true;
        } else {
            forward = false;
        }
    } else if (binding.equals("Walk Backward")) {
        if (value) {
            backward = true;
        } else {
            backward = false;
        }
    } else if (binding.equals("Jump")) {
        character.jump();
    }
}

private PhysicsSpace getPhysicsSpace() {
    return bulletAppState.getPhysicsSpace();
}

private void setUpLight() {
    // We add light so we see the scene
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(1.3f));
    rootNode.addLight(al);

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
    rootNode.addLight(dl);
}

}

What is your question, exactly ? Code is not that much explicit !

You know the concept of “TLDR”? Btw your code lacks abstraction;)

Hey im new to Jmonkey engine.This code is working fine for some extent.please copy that and run.what i want is this.whens i click “S” key i want rotate the robot…

You should ask some question if you want answers. Simply stating “try it, you will see” will just get people to ignore it. They simply don’t have time.

Also wrapping it in the code/java tags would make it a heck of a lot easier to read.

edit: nvm