Moving camera with mouse click and drag

I have my actionlistener on and working, mapped WASD for movement and wanted to add mouse control to turn when click+drag and look up and down.

The mouse is visible unless you click, then drag (then goes invisible), I record previous mousePos X then use the difference to rotate the camera. here is the code for turning:

This code works great to get the camera to turn using the mouse:

if (mouseClick) { //this listen for MouseInput.BUTTON_LEFT, set to true if left mouse button is pressed
if (mousebuttondown) { // my own bool var that tells me the button is already pressed so now testing for movement.
mouseposx = inputManager.getCursorPosition().x; // getting new mouse X value, old value is set to oldmouseposx below for next round
if (oldmouseposx != mouseposx) {
Quaternion rotateR = new Quaternion().fromAngleAxis(((oldmouseposx - mouseposx)/5) * tpf, Vector3f.UNIT_Y); // I divide by 5 because it went too fast (mouse sensibility)
mousebuttondown = true;
oldmouseposx = inputManager.getCursorPosition().x;

    } else { mousebuttondown = false; inputManager.setCursorVisible(true);}
    playerControl.setViewDirection(viewDirection); // turn!

The problem is I am trying to get it to look up/down too, doing the same thing but with the Y value of the mouse and Vector3f.UNIT_X but all it does it switch my view 180deg.

Any idea?

Here is the code I tried to look up and down:

mouseposy = inputManager.getCursorPosition().y;
if (oldmouseposy != mouseposy) {
Quaternion rotateR = new Quaternion().fromAngleAxis(((oldmouseposy - mouseposy)/2) * tpf, Vector3f.UNIT_X);



Which camera are you using?

flyByCamera does this by default, afaik

not sure what it is called, not the flycam though:

playerNode = new Node(“the player”);
playerNode.setLocalTranslation(new Vector3f(0, 6, 0));
playerControl = new BetterCharacterControl(1.5f, 4, 33f);
playerControl.setJumpForce(new Vector3f(0, 300, 0));
playerControl.setGravity(new Vector3f(0, -10, 0));

camNode = new CameraNode(“CamNode”, cam);
camNode.setLocalTranslation(new Vector3f(0, 4, -1));
Quaternion quat = new Quaternion();
quat.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y);