Camera jumping when adding new object to target group

I am trying to change targets by adding them to a target group and Lerping in/out their weights and radius to create a smooth transition. However, the camera jumps as soon as the new target is added despite the weight starting at 0. Any settings I am missing that would create a smooth transition?

private IEnumerator AddToTargetGroup(Transform futureTarget, float weight, float radius)
    {
        cineTargetGroup.AddMember(futureTarget, 0f, startTargetRadius);
        int index = cineTargetGroup.FindMember(futureTarget);
        //CinemachineTargetGroup.Target t = cineTargetGroup.m_Targets[index];
        Debug.Log("Index is " + index);
        float timeElapsed = 0f;
        while (timeElapsed < lerpDuration)
        {
            Debug.Log("in coroutine");
            timeElapsed += Time.deltaTime;
            //t.weight = Mathf.Lerp(0f, weight, timeElapsed / lerpDuration);
            cineTargetGroup.m_Targets[index].weight = Mathf.Lerp(0f, weight, timeElapsed / lerpDuration);
            cineTargetGroup.m_Targets[index].radius = Mathf.Lerp(startTargetRadius, radius, timeElapsed / lerpDuration);
            Debug.Log("Weight is " + cineTargetGroup.m_Targets[index].weight);

            yield return null;
        }
        cineTargetGroup.m_Targets[index].weight = weight;
        cineTargetGroup.m_Targets[index].radius = radius;
    }
    private IEnumerator RemoveFromTargetGroup(Transform currentTarget)
    {
        int index = cineTargetGroup.FindMember(currentTarget);
        //CinemachineTargetGroup.Target t = cineTargetGroup.m_Targets[index];
        float weight = cineTargetGroup.m_Targets[index].weight;
        float radius = cineTargetGroup.m_Targets[index].radius;

        float timeElapsed = 0f;
        while (timeElapsed < lerpDuration)
        {
            cineTargetGroup.m_Targets[index].weight = Mathf.Lerp(weight, 0f, timeElapsed / lerpDuration);
            cineTargetGroup.m_Targets[index].radius = Mathf.Lerp(radius, startTargetRadius, timeElapsed / lerpDuration);
            timeElapsed += Time.deltaTime;
            yield return null;
        }
        cineTargetGroup.m_Targets[index].weight = 0f;
        cineTargetGroup.m_Targets[index].radius = startTargetRadius;
        cineTargetGroup.RemoveMember(currentTarget);
    }

Naturally, as soon as I posted this I realized it was coming from my player rotation instantly changing to face the new target. Go cinemachine

1 Like