- Home /
Vertical Camera Orbit
Hi everyone!
I'm trying to get a camera to orbit around an object. It always works horizontally, but I can't get it to work vertically. This is the code that makes it work horizontally only (although jaggy):
 using UnityEngine;
 
 public class CameraController : MonoBehaviour
 {
     public GameObject player;
     public float rotationSpeed;
 
     private Vector3 offset;
 
     void Start()
     {
         offset = transform.position - player.transform.position;
     }
 
     void LateUpdate()
     {
         Quaternion cameraTurnAngle = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * rotationSpeed, Vector3.up);
 
         offset = cameraTurnAngle * offset;
 
         transform.position = player.transform.position + offset;
         transform.LookAt(player.transform);
     }
 }
I tried doing it the same way vertically, but it only works as long as I don't orbit horizontally. If I do that, the camera will rotate around an axis parallel to the object. The horizontal rotation still works in that case though. I feel like I somehow need to take the horizontal rotation into account while doing the vertical rotation, because it needs to be a combination of y and z rotation at that point. How can I do this?
Your answer
 
 
             Follow this Question
Related Questions
translate a gameobjects position.y based on another gameobjects position .z 1 Answer
Possible way to improve performance moving large hierarchies? 1 Answer
How Do I Give Two Objects the Same Transform? 1 Answer
Issues with copying Y axisrotation of another object 2 Answers
How to force camera rotation? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                