Several First-Person camera pitfalls (speed and angle) [jME3]

I know this is pretty old, but I’m also messing around with a game and ran into this problem.
I found most of these solutions to be unnecessarily complicated.
If you just want a hacky fix that works here’s what i did.

public void fixOrientation(){
if(cam.getDirection().getY() > 0.75)
cam.lookAtDirection(new Vector3f(cam.getDirection().getX(),0.75f,cam.getDirection().getZ()),new Vector3f(cam.getUp().getX(),1,cam.getUp().getZ()));
if(cam.getDirection().getY() < -0.75)
cam.lookAtDirection(new Vector3f(cam.getDirection().getX(),-0.75f,cam.getDirection().getZ()),new Vector3f(cam.getUp().getX(),1,cam.getUp().getZ()));
}

Call this in simple update in the hello collision tutorial; after the if’s and before the call to setWalkDirection().
Additionally setting the Y component of the walk direction to zero will fix the “flight” problem as well as other buggy behaviors that come from getting the walk direction directly from the cam direction.
Additionally the “flipping over” behavior he was experiencing was caused by setting the Y component of the up axis to 0 instead of 1.

//Normans code
public void simpleUpdate(float tpf) {
camDir.set(cam.getDirection()).multLocal(0.6f);
camLeft.set(cam.getLeft()).multLocal(0.4f);
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(camLeft);
}
if (right) {
walkDirection.addLocal(camLeft.negate());
}
if (up) {
walkDirection.addLocal(camDir);
}
if (down) {
walkDirection.addLocal(camDir.negate());
}
//my fixes
fixOrientation();
walkDirection.setY(0);//Fix “flight”
//end my fixes
player.setWalkDirection(walkDirection);

    cam.setLocation(player.getPhysicsLocation());
}

You can mess with the inclination as you want. Here i have it set to 0.75. Although If you set it too high it will start getting buggy. I think this is due to the camera moving faster than the update function can validate it.
0 - 0.9 are safe.

I hope this is helpful.

1 Like