Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

CinemachineFreeLook : adjust Recentering during runtime.

Discussion in 'Cinemachine' started by canis, Oct 1, 2018.

  1. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    70
    Hi, question about CinemachineFreeLook.cs again.
    I'm try to define 2 different recentering timing for my follow target during runtime.

    what I want to achieve is set a longer m_WaitTime & m_RecenteringTime during my character idle.
    but much faster during move.

    basically I want the full control the recenter trigger time.
    I found the public parameters in CinemachineFreeLook.cs
    { m_YAxisRecentering, m_RecenterToTargetHeading }

    Then I found the API that related to recentering :
    https://docs.unity3d.com/Packages/c....1/api/Cinemachine.AxisState.Recentering.html

    and my question are :
    1. Is there a way to detect the recentering state ? in process or reached target...etc
    2. [if above not work] how can I control the recentering manually ? DoRecentering ? each update ?
      sorry, not much information I can found on that document.
    3. May be I should start to change that values during run-time directly. (Just realize during asking question)
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    4,141
    You can control the recentering yourself through script. Disable the automatic recentering, and add a script to the FreeLook to bring the axis.Value back to 0 in any manner you like. You can implement this in Update() or LateUpdate(), as you prefer.
     
    canis likes this.
  3. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    70
    Ar~ thanks, so obvious, what a silly me.
     
  4. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    378
    Hi,

    old post, but still relevant I think:

    What if I want to adjust the actual recentering values themselves, it seems that no matter how I try to set these values, it's ignored.

    I tried, directly, I tried to create a new Recentering and assign it, but nothing is working.

    Am I missing the obvious here?

    Bye,

    Jean
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    4,141
    It should work at runtime. What values exactly are you trying to change? Can you show the code?
     
  6. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    378
    Hi,

    here the code.

    Code (CSharp):
    1.  
    2.         protected void SetAxisSettings(ref AxisState axisSettings)
    3.         {
    4.        
    5.                 axisSettings.m_Recentering.m_enabled = true;
    6.             }  
    7.  
    Bye,

    Jean
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    4,141
    And how do you call that? You might be enabling only a local copy of AxisState, instead of the one inside the FreeLook.
     
    Last edited: Apr 6, 2020
  8. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    378
    Hi,

    no, I am not on a copy.

    I made a script that shows the problem, so you can replicate it on your end.

    Code (CSharp):
    1. using Cinemachine;
    2. using UnityEngine;
    3.  
    4. public class NewBehaviourScript : MonoBehaviour
    5. {
    6.     public CinemachineFreeLook freelook;
    7.    
    8.     // doesn't work
    9.     public bool ForceRecenter;
    10.     // doesn't work
    11.     public bool IsRecentered;
    12.  
    13.     //Works
    14.     public float readYAxisValue;
    15.    
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         // doesn't work
    21.         freelook.m_YAxis.m_Recentering.m_enabled = ForceRecenter;
    22.  
    23.         // doesn't work
    24.         IsRecentered = freelook.m_YAxis.m_Recentering.m_enabled;
    25.  
    26.         // works
    27.         readYAxisValue =  freelook.m_YAxis.Value;
    28.        
    29.     }
    30. }
    Bye,

    Jean
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    4,141
    It's because you have to use
    freelook.m_YAxisRecentering
    instead of
    freelook.m_YAxis.m_Recentering
    .
    Sorry, it's historical :(
     
  10. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    378
    Hi,

    ...ouch... Cinemachine api is hands down the most cryptic I have seen in the so many years of porting api to PlayMaker... sometimes it seems complex on purpose... :)

    so what's the use of the "m_YAxis.m_Recentering" then? is that a dead end of the api?

    Bye,

    Jean
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    4,141
    ...ouch... my turn
    The m_Recentering member is used in other contexts - in FreeLook Y Axis, it's ignored. Why are there 2 members? Historical reasons. Sorry, but sometimes it's just that way.
     
  12. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    378
    Hi,

    Ahh, so I can still implement that for other component implement this axis class, good to know. thanks :)

    Bye,

    Jean
     
unityunity