# FlyCam how can i limit the up/down rotation to 90°

Hi i use the flyCam from the collision tutorial how can i limit the camerarotation of up down to 90°?

Check its rotation each frame and just set it back to 90deg when its above that.

good theory but i dont know how to code it

can u give me a little example please?

[java]if(cam.getUp().getY() < 0.15f){

cam.setAxes(cam.getLeft(), new Vector3f(cam.getUp().getX(), 0.15f, cam.getUp().getZ()), cam.getDirection());

}[/java]

its for lookdown but it worked not correctly when i rotate the camera left and right only when i look at the z axis

has no one solve this problem before?

and can give me a look on your code?

well it’s not a problem really , you just have to do it

You want to limit the rotation of the camera on the x axis to 90° up and 90° down

So basically , you have on each frame to check its rotation and set it to 90 if it’s over like Normen said.

pseudo code in simpleUpdate

``` //this will return the actual rotation angles in radians float[] angles=new float[3]; cam.getRotation().toAngles(angles); //check the x rotation if(angles[0]>FastMath.HALF_PI){ angles[0]=FastMath.HALF_PI; cam.setRotation(tmpQuat.fromAngles(angles)); }else if(angles[0]<-FastMath.HALF_PI){ angles[0]=-FastMath.HALF_PI; cam.setRotation(tmpQuat.fromAngles(angles)); } ```

tmpQuat is some temp quaternion variable in your class to avoid instancing a new quaternion each frame and that’s pretty much it

2 Likes

thank you so much man that helps me so much in my developing its dificult to understand it when i not see an example code i understand the logic idea but i dont know the functions to code it

kany said:
thank you so much man that helps me so much in my developing its dificult to understand it when i not see an example code i understand the logic idea but i dont know the functions to code it

That is kind of what we are talking about, you should build up this ability so you are not completely helpless each time you want to do something and have to ask somebody "can I haz code??" Get used to code completion, javadoc et al.
1 Like

when i have a problem i dont ask immediately give me code!

i have read many and searching the forum and trying hours by my self to solve this problem

then it came the point i think its better to ask

you said

Check its rotation each frame and just set it back to 90deg when its above that.
iam thankfully for your quick answer but i dont know how to check when u have give me these line: [java]cam.getRotation().toAngles(angles);[/java] then i had understand it

sry for my bad english xD

Yes, ok. Next time I will write a complete tutorial just for the problem asked about, expecting everybody to be completely oblivious of all documentation and javadoc we wrote already. Guess some people will tell me then that they are not stupid but well, you can’t please everyone I guess…