Hello guys, I’ve some trouble with a First Person Shooter project and after 3 days of ineffective “commits”, I turn to you to find a solution, and a deep understanding of the flyCam system.
Into my project, i’ve made some AppStates to transit between Main Menu, Options menu, principally build with Nifty GUI. And for every elements, I desactivate the flyCam and when I change between states, I systematically clear the mapping of the inputs (because it’s the only way i’ve found, tell me if i’m wrong).
And I’ve found in the TestQ3.java a good example of the way I want to use the FlyBycamera and all. But, I’ve try to reactivate by every way the flyCam and it never run like I want. When I done that :
Into the init function :
[java]
bulletAppState = new BulletAppState();
app.getStateManager().attach(bulletAppState);
bulletAppState.initialize(app.getStateManager(), app);
bulletAppState.setEnabled(true);
// Init flycam
//flyCam = new FlyByCamera(cam);
flyCam.setEnabled(true);
flyCam.setDragToRotate(false);
flyCam.setMoveSpeed(100);
this.cam.setFrustumFar(2000);
cam.updateViewProjection();
// Init Space with Floor and boxes and stuff
this.createPhysicsWorld(bulletAppState.getPhysicsSpace());
// Add a physics character to the world
player = new CharacterControl(new CapsuleCollisionShape(1, 1), .1f);
player.setPhysicsLocation(new Vector3f(0, 1, 0));
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
characterNode = new Node(“character node”);
Spatial model = StaticGraphGems.Cube(0, 1, 0, 0.5f, 1.8f, .1f, assetManager, “Caract”, ColorRGBA.Green);
characterNode.addControl(player);
getPhysicsSpace().add(player);
graphNode.attachChild(characterNode);
characterNode.attachChild(model);
nodeCam = new CameraNode("CamNode", cam);
nodeCam.setControlDir(ControlDirection.SpatialToCamera);
nodeCam.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y);
characterNode.attachChild(nodeCam);
[/java]
Into the update while :
[java]
Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
walkDirection.set(0,0,0);
if (leftStrafe) {
walkDirection.addLocal(camLeft);
} else
if (rightStrafe) {
walkDirection.addLocal(camLeft.negate());
}
if (forward) {
walkDirection.addLocal(camDir);
} else
if (backward) {
walkDirection.addLocal(camDir.negate());
}
player.setWalkDirection(walkDirection);
cam.setLocation(player.getPhysicsLocation());
[/java]
Into the keyInit :
[java]
inputManager.addMapping(“Strafe Left”, new KeyTrigger(KeyInput.KEY_Q));
inputManager.addMapping(“Strafe Right”, new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping(“Walk Forward”, new KeyTrigger(KeyInput.KEY_Z));
inputManager.addMapping(“Walk Backward”, new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping(“Jump”, new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping(“Rotate Left”, new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping(“Rotate Right”, new KeyTrigger(KeyInput.KEY_E));
inputManager.addMapping(“BackMenu”, ConfigLoader.mainMenuKey.get(0));
inputManager.addListener(ActionListener, “Strafe Left”);
inputManager.addListener(ActionListener, “Strafe Right”);
inputManager.addListener(ActionListener, “Rotate Left”);
inputManager.addListener(ActionListener, “Rotate Right”);
inputManager.addListener(ActionListener, “Walk Forward”);
inputManager.addListener(ActionListener, “Walk Backward”);
inputManager.addListener(ActionListener, “Jump”);
inputManager.addListener(ActionListener, “BackMenu”);
flyCam.registerWithInput(inputManager);
[/java]
Into the Action Listener :
[java]
if (binding.equals(“Strafe Left”)) {
if (value) {
leftStrafe = true;
} else {
leftStrafe = false;
}
} else if (binding.equals(“Strafe Right”)) {
if (value) {
rightStrafe = true;
} else {
rightStrafe = false;
}
} else if (binding.equals(“Rotate Left”)) {
if (value) {
leftRotate = true;
} else {
leftRotate = false;
}
} else if (binding.equals(“Rotate Right”)) {
if (value) {
rightRotate = true;
} else {
rightRotate = false;
}
} else if (binding.equals(“Walk Forward”)) {
if (value) {
forward = true;
} else {
forward = false;
}
} else if (binding.equals(“Walk Backward”)) {
if (value) {
backward = true;
} else {
backward = false;
}
} else if (binding.equals(“Jump”)) {
player.jump();
} else if (binding.equals(“BackMenu”) && value){
app.getStateManager().getState(TutorialState.class).setEnabled(false);
app.getStateManager().getState(BulletAppState.class).setEnabled(false);
app.getStateManager().getState(MainMenuState.class).setEnabled(true);
}
}
[/java]
I can see the can first person camera and access to the mouse wheel effect on the cam (I’ve never understant what’s effect? A zoom or something?), but I can’t rotate the view with the mouse. I think something has been lost between states but I can’t figure what.
Anyone can help me? To turn on the flyByCamera or recreate a complete first person camera?