- Home /
Rotate camera
I have camera as child of player object, this is working great but now when I shot I want to add some recoil so I rotate camera to left/right for a bit. Now I want to lerp it to direction player is looking.
That would be simple if I wanted to rotate it on all three axis, but I want to rotate to same direction as player only on X and Y coordinates.
Imagine 2D game where you are looking from top, when you click something camera rotates to right for a bit and then lerp back to left. Here you cannot set camera angle to be same as player angle because then camera will not be looking to player anymore but into empty space because Z degree was set to same as player and camera will be looking above player. A bit hard to imagine but I tried my best explaining
Answer by ScroodgeM · Aug 29, 2012 at 10:06 PM
cameraTransform.rotation = playerTransform.rotation * Quaternion.EulerAngles(90f, 0f, 0f);
this will set camera's rotation Z to player's Y. now add offset you needed.
PS it's bad practice to swap axis to objects.
Z should be forward, Y is up and X is right.
Your answer
Follow this Question
Related Questions
easing camera rotation after mouse up? 0 Answers
canvas screen space camera rotation issue 0 Answers
How to make a camera "point" at an object. 1 Answer
smoothly rotate camera around an object with momentum 0 Answers
How to force camera rotation? 1 Answer