Search Unity

Its possible change deadzone from CineMachine by script?

Discussion in 'Cinemachine' started by LoveraSantiago, Nov 20, 2017.

  1. LoveraSantiago

    LoveraSantiago

    Joined:
    Nov 20, 2017
    Posts:
    18
    Hi all.

    I would like to change deadzone width from my Cinemachine.

    How I can get a reference to Cinemachine object type?
    It has any property "setter" to change deadzones values?
    I'm using in 2D way, to follow my player.

    Thanks.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Yes, there is an API for this. See ScriptingExample.cs in the Examples folder for some sample code. You'll need to do something like this:
    Code (CSharp):
    1.         var composer = vcam.GetCinemachineComponent<CinemachineComposer>();
    2.         composer.m_DeadZoneWidth = 0.30f;
    3.         composer.m_DeadZoneHeight = 0.35f;
     
    Last edited: Jan 11, 2018
    strobone21 and bowserscastle like this.
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    And if you're using a vcam with FramingTransposer, it would be
    Code (CSharp):
    1.         var composer = vcam.GetCinemachineComponent<CinemachineFramingTransposer>();
    2.         composer.m_DeadZoneWidth = 0.30f;
    3.         composer.m_DeadZoneHeight = 0.35f;
     
    Last edited: Nov 22, 2017
  4. LoveraSantiago

    LoveraSantiago

    Joined:
    Nov 20, 2017
    Posts:
    18
    Great Gregory!
    It works with CinemachineFramingTransposer.

    Thanks a lot!
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Glad it's working. I noticed an error in my post, however. You should be using GetCinemachineComponent<>, not AddCinemachineComponent<>. Both will work, but the first will perform better. I've edited my original post to correct it.
     
  6. Salim

    Salim

    Joined:
    Apr 25, 2011
    Posts:
    148
    Hello!
    I would like to do the same with the FreeLook Camera; changing the Dead Zone for the composer in all 3 rigs (top, middle, bottom) by script. Is this possible?
    Also, is there a place where we can find all the scripting API for Cinemachine? (I could not find anything online)
    Thank you!
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Have a look at ScriptingExample.cs, that comes with the Cinemachine example scenes. It will show you what you need to do. There is an API manual that comes with the package - look in the Cinemachine folder in your project.
     
  8. Salim

    Salim

    Joined:
    Apr 25, 2011
    Posts:
    148
    Thank you kindly!
     
  9. LucasVaz

    LucasVaz

    Joined:
    Jan 17, 2019
    Posts:
    4
    Hello i would like to reduce the Y Damping while my character is falling, i am having difficult to add a script that does that to my camera, is there any way to add a behavior script to the virtual camera?
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Just add it. Have a look at ScriptingExample.cs, that comes with the Cinemachine example scenes. It will give you some clues about how to access fields like damping, inside the vcam's composer or transposer.

    Another (possibly better) option would be to create a second vcam, with settings tuned for falling, and blend to it when the character is falling.
     
    LucasVaz likes this.
  11. LucasVaz

    LucasVaz

    Joined:
    Jan 17, 2019
    Posts:
    4
    It worked thank you for your help and suggestion.
     
  12. LucasVaz

    LucasVaz

    Joined:
    Jan 17, 2019
    Posts:
    4
    I was able to perform the changes by code, i was also trying to blend between the two cameras, is there a way to trigger the blend without a state driven camera?
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Raise the priority of the falling vcam when falling, and lower it when not falling.
     
    LucasVaz likes this.
  14. LucasVaz

    LucasVaz

    Joined:
    Jan 17, 2019
    Posts:
    4
    It worked, thank you!
     
  15. Rocketman_Dan

    Rocketman_Dan

    Joined:
    Apr 3, 2015
    Posts:
    4
    Anyone know how to do this with a free camera? GetCinemachineComponent doesn't seem to exist. This may be just been updated or a quirk of using free camera? Regardless I can't seem to find anywhere else that mentions changeing dead zones in code.
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Have a look at the Scripting scene in CinemachineExamples. That should put you on the right path.