Ok I did some digging into what was going on and this is what I found…
It is all going wrong in this code in TrackTarget method of TargetTracking.cs
else if (settings.BindingMode != BindingMode.LazyFollow)
{
var relative = (Quaternion.Inverse(PreviousReferenceOrientation)
* targetOrientation).eulerAngles;
for (int i = 0; i < 3; ++i)
{
if (relative[i] > 180)
relative[i] -= 360;
if (Mathf.Abs(relative[i]) < 0.01f) // correct for precision drift
relative[i] = 0;
}
relative = component.VirtualCamera.DetachedFollowTargetDamp(
relative, settings.GetEffectiveRotationDamping(), deltaTime);
dampedOrientation = PreviousReferenceOrientation * Quaternion.Euler(relative);
}
In here relative is always 0,0,0… This is because PreviousReferenceOrientation is always 0,0,0
So why is Previous Reference Orientation always 0… Well its because of this code
public void InitStateInfo(
CinemachineComponentBase component, float deltaTime,
BindingMode bindingMode, Vector3 up)
{
Debug.Log($"Initializing Camera {component.gameObject.name} State is Valid {component.VirtualCamera.PreviousStateIsValid}");
bool prevStateValid = deltaTime >= 0 && component.VirtualCamera.PreviousStateIsValid;
if (component.VirtualCamera.Name == "Aim") Debug.Log("DebugME");
if (m_PreviousTarget != component.FollowTarget || !prevStateValid)
{
m_PreviousTarget = component.FollowTarget;
m_TargetOrientationOnAssign = component.FollowTargetRotation;
//if (component.VirtualCamera.Name == "Aim") PreviousReferenceOrientation = GetReferenceOrientation(component, bindingMode, up);
}
if (!prevStateValid)
{
PreviousTargetPosition = component.FollowTargetPosition;
Debug.Log($"Initializing Camera State {component.gameObject.name}");
PreviousReferenceOrientation = GetReferenceOrientation(component, bindingMode, up);
}
In this code the previousStateValid is always true and so we never call GetReferenceOrientation
You can see from the code above I added a commented out code, but when this code is active it works just fine…
The one camera that does work gets initialized here with PreviousStateIsValid = true…
I tried forcing PreviousStateValid = false prior to activating the camera and unfortunately it is set back to true by
InternalUpdateCameraState(Vector3 worldUp, float deltaTime) before InitStateInfo is called…
I am guessing our root cause is the way we load cinimachine on project load…
Do you have any suggestions on how I can make sure that when InitStateInfo is called we can force an update?