Binding mouse to KeyNodeLookUp etc

ok, so I have an InputHandler called from here;

   private void buildControls() {
      input = new InputHandlerGame(playerNode, chaser.getCamNode(), settings.getRenderer());

that looks like this;

package test;

import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.action.KeyNodeBackwardAction;
import com.jme.input.action.KeyNodeForwardAction;
import com.jme.input.action.KeyNodeLookDownAction;
import com.jme.input.action.KeyNodeLookUpAction;
import com.jme.input.action.KeyNodeRotateLeftAction;
import com.jme.input.action.KeyNodeStrafeLeftAction;
import com.jme.input.action.KeyNodeStrafeRightAction;
import com.jme.scene.Spatial;

public class InputHandlerGame extends InputHandler {
   public InputHandlerGame (Spatial playersNode, Spatial cameraNode, String api) {
        setActions(playersNode, cameraNode);
   private void setKeyBindings(String api) {
        KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
        keyboard.set("forward", KeyInput.KEY_W);
        keyboard.set("backward", KeyInput.KEY_S);
        keyboard.set("strafeRight", KeyInput.KEY_D);
        keyboard.set("strafeLeft", KeyInput.KEY_A);
   private void setActions(Spatial playersNode, Spatial camerasNode) {
        KeyNodeForwardAction forward = new KeyNodeForwardAction(playersNode, 30f);
        addAction(forward, "forward", true);
        KeyNodeBackwardAction backward = new KeyNodeBackwardAction(playersNode, 30f);
        addAction(backward, "backward", true);
        KeyNodeStrafeRightAction strafeRight = new KeyNodeStrafeRightAction(playersNode, 30f);
        addAction(strafeRight, "strafeRight", true);
        KeyNodeStrafeLeftAction strafeLeft = new KeyNodeStrafeLeftAction(playersNode, 30f);
        addAction(strafeLeft, "strafeLeft", true);
        KeyNodeRotateLeftAction rotateRight = new KeyNodeRotateLeftAction(playersNode, 1.0f);
        addAction(rotateRight, "rotateRight", true);
        KeyNodeRotateLeftAction rotateLeft = new KeyNodeRotateLeftAction(playersNode, 1.0f);
        addAction(rotateLeft, "rotateLeft", true);
        KeyNodeLookUpAction lookUp = new KeyNodeLookUpAction(camerasNode, 1.0f);
        addAction(lookUp, "lookUp", true);
        KeyNodeLookDownAction lookDown = new KeyNodeLookDownAction(camerasNode, 1.0f);
        addAction(lookDown, "lookDown", true);


As you can see I have got bindings for WASD but not the mouse for controlling the rotation of the playerNode and camNode. How do I bind these properly?

Also I am curious why this


can anyone tell me why it is there because as far as I can see it doesn't get used?

WASD work. Something funny though is that I have two boxes rendered one is a player that moves and has the camera attached to it and the other is there for reference (there is only these two boxes rendered) Anyway I couldn't figure out why on earth my boxNode was moving when it was supposed to be my playerNode, I was going insane thinking why my box was moving. Then I remembered that the playerNode had the camNode attached as a child and it was actually the playerNode AND the camNode moving not the boxNode!  XD doh! Haha I kicked myself when I realised it. It makes scense though too because I wondered why all the controls were reversed!




is there cos I lifted this out of the FlagRushInputHandler

So I have been looking around and I have found a few things.

Would I bind mouse  movements using MouseAxisBinding? If so how would I accomplish this in my above example?

Also could someone let me know if I am going about this in the right way (ie binding mouse movements to-

  • KeyNodeRotateLeftAction, KeyNodeRotateRightAction, KeyNodeLookUp, KeyNodeLookDown?

    Also I have noticed that I had two KeyNodeRotateLeftAction's and now there is one right and one left.

    Edit: I have mapped all the actions to keys and it all behaves as I want, I just need to now take some of the actions and map them to the mouse x/y axes instead of keys, can someone help me do this please I cannot find how to accomplish it?  :slight_smile:

there are many different ways to handle input.

MouseAxisBinding is used with the GameControl system.

you can tak a look at jmetest.input.controls.TestControls to see how to use them.

I often used that system and its quite flexible. You can add Key and Mouse events to the same Action.

You could also implement your own MouseNodeRotateLeftAction like KeyNodeRotateLeftAction, just extend from InputAction.

The NodeMouseLook class did what I wanted, I just had to find it  :slight_smile:

What I ended up doing though was, modifying the NodeMouseLook class so that I could assign left/right rotation to one node and up/down rotation to another node, as in its current state it only allows rotation of one node.