Search Unity

Setting up a simple automatic orbiting camera

Discussion in 'Cinemachine' started by JoeysLucky22, Jul 5, 2019.

  1. JoeysLucky22

    JoeysLucky22

    Joined:
    May 11, 2013
    Posts:
    15
    I'm just getting used to Cinemachine and I'm really liking it! Setting up following dolly shots is pretty intuitive but I'm really struggling with something as simple as setting up a "continually orbit around this target" shot that's not based off of a player's input. Nothing's really stopping me from making a simple rotation script to do it but I really like cinemachine's semi-code-free approach to cameras and would prefer some way to do this within the inspector.

    I have a virtual camera with an Orbital Transposer. I don't want to map to a mouse input so I removed the input axis name but I do want to lerp the value with a speed. Is there something I'm just missing or do I need to write my own script to handle this?

    Previously I've set up circular looped smooth path with a dolly cart but that's a bit too cumbersome to set up. An orbital transposer looks like exactly what I want, it's just unclear how to set it up so that it orbits automatically?
     
  2. JoeysLucky22

    JoeysLucky22

    Joined:
    May 11, 2013
    Posts:
    15
    This is the current script I'm using. I attach this to the virtual camera and set my speed to whatever. This method works fine, would just be nice not having to do this step manually (Scripting isn't my forte)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Cinemachine;
    5.  
    6. public class FilmOrbit : MonoBehaviour
    7. {
    8.     public float speed = 10f;
    9.  
    10.     private Cinemachine.CinemachineVirtualCamera m_VirtualCam;
    11.  
    12.     void Start(){
    13.         if(GetComponent<Cinemachine.CinemachineVirtualCamera>())
    14.             m_VirtualCam = GetComponent<Cinemachine.CinemachineVirtualCamera>();
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         if(m_VirtualCam.GetCinemachineComponent<CinemachineOrbitalTransposer>())
    20.             m_VirtualCam.GetCinemachineComponent<CinemachineOrbitalTransposer>().m_XAxis.Value += Time.deltaTime * speed;
    21.     }
    22. }
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You're asking for a specialty thing, so you're stuck doing a little scripting. Your solution is just what I would have suggested, only I would modify it slightly for safety and performance, as follows:

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class FilmOrbit : MonoBehaviour
    5. {
    6.     public float speed = 10f;
    7.  
    8.     private CinemachineOrbitalTransposer m_orbital;
    9.  
    10.     void Start()
    11.     {
    12.         var vcam = GetComponent<CinemachineVirtualCamera>();
    13.         if (vcam != null)
    14.             m_orbital = vcam.GetCinemachineComponent<CinemachineOrbitalTransposer>();
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         if (m_orbital != null)
    20.             m_orbital.m_XAxis.Value += Time.deltaTime * speed;
    21.     }
    22. }
     
    MasonWheeler and JoeysLucky22 like this.
  4. AerionXI

    AerionXI

    Joined:
    Jul 20, 2020
    Posts:
    482
    How can I incorporate the mouse Y Orbit into this as well? Trying to make this work on both Axes. Thank you so kindly!
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You can use a vcam with FramingTransposer in Body and DoNothing in Aim. Set the Follow target to be the thing you want the camera to orbit around. To make the camera orbit in any direction, your script needs to modify vcam.transform.rotation. Try it by hand in the inspector to get an understanding of how it works.