Search Unity

Switching from FreeLook to Aim Camera.

Discussion in 'Cinemachine' started by CrocsxG, Sep 6, 2021.

  1. CrocsxG

    CrocsxG

    Joined:
    Jan 2, 2018
    Posts:
    6
    Hello,

    I would like to have some help regarding my issue. Might be hard to find out from a forum post, but I would like just an idea of where it could come from.

    I have a Orbit Camera (Cinemachine Free Look) that switch to another Aim Camera (Cinemachine Virtual Camera) when the player AIM.

    When in Orbit camera, the player movement are relative to the camera orientation, and when switching to AIM, the camera movement do not affect the player movement, and the player will always look forward.

    Code (CSharp):
    1.  
    2.         public void SwitchToFreeLook()
    3.         {
    4.             _isAimMode = false;
    5.             aimCinemachine.SetActive(false);
    6.             freeLookCinemachine.SetActive(true);
    7.             if (_animator)
    8.             {
    9.                 _animator.SetBool("IsAiming", false);
    10.             }
    11.         }
    12.  
    13.         public void SwitchToAim()
    14.         {
    15.             _isAimMode = true;
    16.             freeLookCinemachine.SetActive(false);
    17.             aimCinemachine.SetActive(true);
    18.             // I tried also this instead
    19.             //freeLookCinemachine.Priority = 0;
    20.             //aimCinemachine.Priority = 1;
    21.             // player will face like camera
    22.             transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, brainCamera.transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
    23.             if (_animator)
    24.             {
    25.                 _animator.SetBool("IsAiming", true);
    26.             }
    27.         }

    I am currently doing the above code to switch from one camera to the other.

    When I transition from the FreeLook to the AIM camera, all work fine, but when coming back to FreeLook, the camera do some weird rotation and I don't understand exactly from where does it come from. Note that with I thought it was the camera repositioning after being set Disabled, but even with priority it does the exact same thing. There is no auto recentering setup, but even with, there is the same thing.



    EDIT :

    I slow down a video I took, and it looks like that the camera start to rotate with the 3rd camera when releasing the AIM, and blend back to the free camera.
    Is there a way to blend from A start point to B end point without caring about the movement of A after the blend started ?

     
    Last edited: Sep 6, 2021
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    If you disable A (i.e. deactivate the GameObject) instead of changing its priority then it will not update its position during the transition.