I am making a 3D LibGDX game. I am using a custom camera controller, based off of the one over here. It takes out the use of delta Y, when determining where to move the player, so that they can stay on the same level whether they are looking up or down.
My problem is that whenever the player looks too far up, or down, the camera kinda starts spazing out. I believe that it is trying to look either strait up, or down. My problem is that I don't want that. In previous projects I have tried to set a limit like so:
if(camera.direction.y + deltaY >= 0.9){
return;
}
(Code might not be exactly correct), but when that happens, the player usually cannot see enough.
There is a link to my code here.
I got my code fixed with the help of one of the fine fellows over at Github. Here is my new FirstPersonCameraController#touchDragged
:
float deltaX = -Gdx.input.getDeltaX() * degreesPerPixel;
float deltaY = -Gdx.input.getDeltaY() * degreesPerPixel;
camera.direction.rotate(camera.up, deltaX);
Vector3 oldPitchAxis = tmp.set(camera.direction).crs(camera.up).nor();
Vector3 newDirection = tmp2.set(camera.direction).rotate(tmp, deltaY);
Vector3 newPitchAxis = tmp3.set(tmp2).crs(camera.up);
if (!newPitchAxis.hasOppositeDirection(oldPitchAxis))
camera.direction.set(newDirection);
(I removed a couple of parts that are specific to my game)