Okay so I used inputManager.clearMappings() then remapped the mouse for rotations and now I’m trying to make it so the wasd keys will move the camera in the direction it is facing with the exception of moving up or down. (I’ll later make the camera move up/down accordingly with the terrain but I’m still learning so its baby steps right now, I can’t wait to help contribute back to the community!)
So any solutions? here is my code.
Basically I load up a player model(box) some terrain and a skybox, then clear mappings on flycam then remap them with the ones i want
[java]package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.math.Quaternion;
import com.jme3.math.;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.scene.;
import com.jme3.input.ChaseCamera;
import com.jme3.input.;
import com.jme3.input.controls.;
import com.jme3.light.*;
import com.jme3.math.Matrix3f;
import com.jme3.math.FastMath;
/**
- test
-
@author shane B.
-
@date April/03/2012
*/
public class Main extends SimpleApplication {
private Spatial player_placeholder;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
public void simpleInitApp() {
//Load Players’ place holder
//Load Player model
player_placeholder = assetManager.loadModel(“Models/player_piece.j3o”);
//Load Players Materials
Material player_placeholder_mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
//Attach materials to the player
player_placeholder_mat.setTexture(“ColorMap”,assetManager.loadTexture(“Materials/Bricks.jpg”));
player_placeholder.setMaterial(player_placeholder_mat);
//Attach player to the stage/world
rootNode.attachChild(player_placeholder);
//Move to a start location
player_placeholder.move(0, 1, 0);
//Load skyBox and Floor/ground
Spatial skyBox = assetManager.loadModel(“Scenes/mainSkyBox.j3o”);
rootNode.attachChild(skyBox);
Spatial ground = assetManager.loadModel(“Scenes/mainTerrain.j3o”);
rootNode.attachChild(ground);
//Move gound a bit lower so camera can see by default
ground.move(0,-1,0);
// You must add a directional light to make the model visible!
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
rootNode.addLight(sun);
//Disable cursor view and lock cursor to center of screen to enable FPS views
inputManager.setCursorVisible(false);
flyCam.setEnabled(true);
cam.setLocation(player_placeholder.getLocalTranslation());
cam.setRotation(player_placeholder.getLocalRotation());
//Clear all input mappings – scince we don’t need alot of the preset ones its efficient this way.
inputManager.clearMappings();
//Recreate FPS Mouse mappings
inputManager.addMapping(“FLYCAM_Left”, new MouseAxisTrigger(0, true));
inputManager.addMapping(“FLYCAM_Right”, new MouseAxisTrigger(0, false));
inputManager.addMapping(“FLYCAM_Up”, new MouseAxisTrigger(1, false));
inputManager.addMapping(“FLYCAM_Down”, new MouseAxisTrigger(1, true));
//Add listener for the FPS mouse mappings
inputManager.addListener(analogListener, new String[]{“FLYCAM_Left”, “FLYCAM_Right”, “FLYCAM_Up”, “FLYCAM_Down”});
//Recreate FPS WASD keyboard mappings where the player will move with enviroment
inputManager.addMapping(“Player_forward”, new KeyTrigger(KeyInput.KEY_W));
//Add listener for the WASD keyboard mappings
inputManager.addListener(analogWasdListener, new String[]{“Player_forward”});
}
//FPS mouse Mappings
private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
flyCam.onAnalog(name, value, tpf);
}
};
//FPS WASD keyboard mappings
private AnalogListener analogWasdListener = new AnalogListener(){
public void onAnalog(String name, float value, float tpf){
if(name.equals(“Player_forward”)){
//Move player forward
}
}
};
public void simpleUpdate(float tpf) {
}
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
[/java]