# Libgdx Do a fixed rotation for orthographic camera

I'm trying to rotate my OrthographicCamera in the render loop to a fixed angle, but I can only make the camera spin. This is the code that I have:

in create():

OrthographicCamera camera = new OrthographicCamera();
camera.setToOrtho(true, 100, 100);
camera.position.set(50, 50, 0);
camera.update();


in the render loop:

camera.rotate(30);
camera.update();


The camera keeps spinning each frame. But I'd like the camera to stay at 30 degrees.

https://stackoverflow.com/questions/16509244/set-camera-rotation-in-libgdx

But I don't like it because this code is too drastic. I wonder if there is a more "common" way to do this.

The method camera.rotate() (and all other transformation methods on camera) act on the current state of the camera. So if it's rotated 30 degrees, it will add more 30 degrees to the rotation.

If you want to keep at 30 degrees (but still applying the transform every step), you have to make it look back at whatever it was looking before. Assuming you're using an orthogonal camera for 2D rendering with y pointing down, then this should work:

camera.up.set(0, -1, 0);
camera.direction.set(0, 0, 1);
camera.rotate(30);


If you prefer y pointing up, try:

camera.up.set(0, 1, 0);
camera.direction.set(0, 0, -1);
camera.rotate(30);


Hope this helps you :)

• Thanks for this. I was actually able to use this without the camera.directin.set(0, 0, -1); lines. Commented Jan 16, 2018 at 7:32