Search Unity

Cinemachine scripting reference?

Discussion in 'Cinemachine' started by RendallRen, Mar 15, 2022.

  1. RendallRen

    RendallRen

    Joined:
    Mar 25, 2020
    Posts:
    3
    Is there a scripting reference for Cinemachine?

    When I go here computer says no.
     
  2. RendallRen

    RendallRen

    Joined:
    Mar 25, 2020
    Posts:
    3
    If not, is there a way via script to swap back and forth the Body of a virtual camera from `Cinemachine3rdPersonFollow` to `CinemachineOrbitalTransposer`. Something like (in `AxisState.IInputAxisProvider`)


    Code (CSharp):
    1. private CinemachineOrbitalTransposer orbitalTransposer;
    2. private Cinemachine3rdPersonFollow follow;
    3. float AxisState.IInputAxisProvider.GetAxisValue(int axis)
    4.     {
    5.         bool isOrbiting = lookXYAxis.action.ReadValue<Vector2>().sqrMagnitude > 0.01f;
    6.  
    7.         // While isOrbiting, the camera should orbit
    8.         // Otherwise, the camera should track: follow but not aim
    9.  
    10.        orbitalTransposer.enabled = isOrbiting;
    11.        follower.enabled = !isOrbiting;
    12.  
    13.         switch (axis)
    14.         {
    15.             case 0:
    16.                 return lookXYAxis.action.ReadValue<Vector2>().x;
    17.             case 1:
    18.                 return lookXYAxis.action.ReadValue<Vector2>().y;
    19.             default:
    20.                 return 0;
    21.         }
    22.     }
    23.  
     
  3. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    https://docs.unity3d.com/Packages/com.unity.cinemachine@2.8/manual/index.html


    It would be better to have two vcams and switch between those. One vcam with Cinemachine3rdPersonFollow and one with CinemachineOrbitalTransposer.

    But you can swap using
    Code (CSharp):
    1. vcam.AddCinemachineComponent<Cinemachine3rdPersonFollow>()
    This will replace the current component with same stage (in this case stage is body).
     
    Gregoryl and RendallRen like this.
  4. RendallRen

    RendallRen

    Joined:
    Mar 25, 2020
    Posts:
    3
    Thanks for your reply, gaborkb!

    Ok! For anyone else following who is looking for this, you want to go to that link and then press the Scripting API tab along the top. Or go here: https://docs.unity3d.com/Packages/com.unity.cinemachine@2.8/api/Cinemachine.html

    Thanks for the tip! I'll touch that fire first just to make sure it's hot, then I'll inevitably go your recommended route. :)