我正在尝试使用Jmonkey3 SDk创建fps风格的游戏。我已经从我的角色中创建了一个Node并附加了一个物理角色,然后添加了一个Chase Camera作为我的主要fps视图。向前走,向右走,工作完美。问题是当鼠标到达我看到的模型边缘时不再旋转。此外,相机没有保持fps的正确位置。
基本上相机和模型节点不能用鼠标正常旋转。此外,他的模特并没有“跟着相机上下。”
// Enable a chase cam for this target (typically the player).
flyCam.setEnabled(false);
chaseCam = new ChaseCamera(cam, model, inputManager);
chaseCam.setDragToRotate(false);
chaseCam.setDefaultDistance(.1f);
chaseCam.setInvertVerticalAxis(true);
chaseCam.setLookAtOffset(new Vector3f(-.3f, 2.1f, -.1f));
chaseCam.setDownRotateOnCloseViewOnly(false);
bulletAppState.getPhysicsSpace().addCollisionListener(this);
}
///检查哪个值为true并向该方向移动///
@Override
public void simpleUpdate(float tpf) {
//Check if any walk bools are set to true. Move Character and.
Vector3f camDir = cam.getDirection().mult(0.1f);
Vector3f camLeft = cam.getLeft().mult(0.1f);
camDir.y = 0;
camLeft.y = 0;
viewDirection.set(camDir);
walkDirection.set(0, 0, 0);
if (leftStrafe) {
walkDirection.addLocal(camLeft);
} else
if (rightStrafe) {
walkDirection.addLocal(camLeft.negate());
} else
if (forward) {
walkDirection.addLocal(camDir);
} else
if (backward) {
walkDirection.addLocal(camDir.negate());
}
if (rightRotate) {
viewDirection.addLocal(camLeft.mult(0.02f).negate());
}
physicsCharacter.setWalkDirection(walkDirection);
physicsCharacter.setViewDirection(viewDirection);
cam.lookAt(model.getWorldRotation().multLocal(Vector3f.UNIT_Z.clone()), model.getWorldRotation().multLocal(Vector3f.UNIT_Y.clone()));
}
/// Set a key map for each key control ///
private void setupKeys() {
inputManager.addMapping("Strafe Left",
new KeyTrigger(KeyInput.KEY_A),
new KeyTrigger(KeyInput.KEY_Z));
inputManager.addMapping("Strafe Right",
new KeyTrigger(KeyInput.KEY_E),
new KeyTrigger(KeyInput.KEY_X));
inputManager.addMapping("Walk Forward",
new KeyTrigger(KeyInput.KEY_W),
new KeyTrigger(KeyInput.KEY_UP));
inputManager.addMapping("Walk Backward",
new KeyTrigger(KeyInput.KEY_S),
new KeyTrigger(KeyInput.KEY_DOWN));
inputManager.addMapping("Jump",
new KeyTrigger(KeyInput.KEY_SPACE),
new KeyTrigger(KeyInput.KEY_RETURN));
inputManager.addMapping("Rotate Right",
new KeyTrigger(KeyInput.KEY_D),
new KeyTrigger(KeyInput.KEY_RIGHT));
inputManager.addMapping("Granade",
new KeyTrigger(KeyInput.KEY_G));
inputManager.addMapping("magic", new KeyTrigger(KeyInput.KEY_T));
inputManager.addListener(this, "Strafe Left", "Strafe Right");
inputManager.addListener(this, "Rotate Left", "Rotate Right");
inputManager.addListener(this, "Walk Forward", "Walk Backward");
inputManager.addListener(this, "Jump", "Granade","magic");
}
/// Set Direction values to True or False ///
public void onAction(String binding, boolean value, float tpf) {
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("Granade")) {
if(value) {
Granade = true;
createGranade();
} else {
Granade = false;
}
} else if (binding.equals("magic")){
if(value){
magic = true;
createMagic();
System.out.println(model.getLocalTranslation());
}else{
magic = 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")) {
if(value){
characterJump();
}
}else if (binding.equals("Rotate Right")) {
if (value) {
rightRotate = true;
} else {
rightRotate = false;
}
}
}