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) {
setKeyBindings(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
settings.getRenderer()
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!
Neilos
Edit:
settings.getRenderer()