Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Virtual Camera With Orbital Transposing Revolves Around Target On Start

Discussion in 'Cinemachine' started by DrakeClausen, Dec 16, 2022.

  1. DrakeClausen

    DrakeClausen

    Joined:
    Apr 24, 2022
    Posts:
    7
    The virtual camera in my scene, which is set to Orbital Transposer, revolves around it's target about 180° when I start my scene. The change is near instant but there is a bit of damping between the position that is set as the start position in the inspector and a position about 180° from it. The binding mode is set to Simple Follow With World Up, but the same behavior exists on any of the bindings. How can I make it so that the virtual camera's position set in the inspector before starting the scene is the position it stays at when the scene starts? I am running Unity 2022.2.0f1 and Cinemachine 2.9.4.

    Thank you.
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    It should not happen. I tried to reproduce but could not.

    Could you share more information about your scene (Aim behaviour, images of hierarchy and your CinemachineVirtualCamera)? There may be something else that's causing the issue.

    At Start, you can also try ForceCameraPosition to place the camera:
    Code (CSharp):
    1. vcam.ForceCameraPosition(position, rotation);
     
  3. DrakeClausen

    DrakeClausen

    Joined:
    Apr 24, 2022
    Posts:
    7
    Thanks for the reply @gaborkb . After some troubleshooting it seems that the issue is tied to the X axis input, if I disable the X axis input the issue stops. So, the scene starts with the camera at the position in the inspector and then it quickly jumps due to input coming from the mouse. I suppose this is to be expected, but is there any way to avoid it? Could the mouse be snapped to the position that corresponds with 0 input on scene start or something?
     
    Last edited: Dec 17, 2022
  4. DrakeClausen

    DrakeClausen

    Joined:
    Apr 24, 2022
    Posts:
    7
    After troubleshooting a bit more I found a solution to my issue. Since the camera X axis input is based on the mouse's delta it should have an input of 0 so long it is not actively moving on scene start, but for some reason it sends a non-zero input on start even if the mouse is still. By delaying the enabling of the camera's Cinemachine Input Provider it misses the erroneous non-zero X axis input that occurs on start. Adding at least a 2 frame enabling delay seems to do the trick.

    Here is the code used for the script which is attached to the offending virtual camera.

    Code (CSharp):
    1. public class CameraInputDelay : MonoBehaviour
    2. {
    3.     private CinemachineInputProvider inputProvider;
    4.  
    5.     private void Start()
    6.     {
    7.         inputProvider = GetComponent<CinemachineInputProvider>();
    8.         StartCoroutine(EnableInputProvider(2));
    9.     }
    10.  
    11.     IEnumerator EnableInputProvider(int frames)
    12.     {
    13.         for (int i = 0; i < frames; i++)
    14.         {
    15.             yield return null;
    16.         }
    17.         inputProvider.enabled = true;
    18.     }
    19. }
    P.S. - I have not tested any of this in a build, only in the editor. It's possible the issue may not even exist in a build.
     
    Last edited: Dec 16, 2022