Character Oto can not strafe left or right, change from chase cam to firstperson

Hello Monkeys! :wink:

I’m programming a game (of course) and ran it to some problem. I finally made my character Oto ( as your probably know) able to walk!

My problems are:

  1. Oto can not strafe left or right, only walk forward and backwards and jump.

  2. I’m using a chase cam but I need to make a first person camera and don’t know how to do.

  3. What is the difference between charactercontrol and bettercharactercontrol?

  4. Where i declare player = new charactercontrol, there is a blackline over “chactercontrol”, why? :stuck_out_tongue:

I’ve checked multiple tutorials but not really found what i’m looking for. Here is the relevant code:

[java]
public class Main extends SimpleApplication implements ActionListener {

private CharacterControl player;
private Spatial sceneModel;
private Vector3f walkDirection = new Vector3f();
private RigidBodyControl landscape;
private BulletAppState bulletAppState;
private boolean left=false,right=false,up=false,down=false;

Node playerModel;
ChaseCamera chaseCam;

private Vector3f camDir;
private Vector3f camLeft;

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

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    
    
    sceneModel = assetManager.loadModel("Scenes/sceneModel.j3o");
    CollisionShape sceneShape =
        CollisionShapeFactory.createMeshShape((Node) sceneModel);
    landscape = new RigidBodyControl(sceneShape, 0);
    sceneModel.addControl(landscape);

    initKeys();
    createOto();
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
    rootNode.addLight(dl);
    
    rootNode.attachChild(sceneModel);
    bulletAppState.getPhysicsSpace().add(landscape);
    bulletAppState.getPhysicsSpace().add(player);
}

private void createOto(){
    flyCam.setEnabled(false);
    
    playerModel = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    playerModel.setLocalScale(1.0f);
    playerModel.setLocalTranslation(new Vector3f(1, 10, 1));
    
    chaseCam = new ChaseCamera(cam, playerModel, inputManager);
    chaseCam.setDefaultDistance(37);
    
    CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
    player = new CharacterControl(capsuleShape, 0.05f);
    player.setJumpSpeed(20);
    player.setFallSpeed(30);
    player.setGravity(30);
    
    playerModel.addControl(player);
    
    rootNode.attachChild(playerModel);
}


@Override
public void simpleUpdate(float tpf) {
    camDir = new Vector3f();
    camLeft = new Vector3f();
    camDir = cam.getDirection().clone().multLocal(0.6f);
    camLeft = cam.getLeft().clone().multLocal(0.4f);
    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());
    }
    player.setWalkDirection(walkDirection);
    cam.setLocation(player.getPhysicsLocation());
    
}

@Override
public void simpleRender(RenderManager rm) {
    //TODO: add render code
}

private void initKeys(){
    inputManager.addMapping("Left",new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(this, "Left");
    inputManager.addListener(this, "Right");
    inputManager.addListener(this, "Up");
    inputManager.addListener(this, "Down");
    inputManager.addListener(this, "Jump");
}

public void onAction(String name, boolean isPressed, float tpf) {
    if (name.equals("Strafe Left")){
        if (isPressed){
            left = true;
        }
        else {
            left = false;
        }
    }
    else if (name.equals("Strafe Right")){
        if (isPressed){
            right = true;
        }
        else{
            right = false;
        }
    }
    else if (name.equals("Up")){
        if (isPressed){
            up = true;
        }
        else{
            up = false;
        }
    }
    else if (name.equals("Down")){
        if (isPressed){
            down = true;
        }
        else{
            down = false;
        }
    }
    else if (name.equals("Jump")){
        if (isPressed){
            player.jump();
        }
    }
    
    
}

}

[/java]