Search Unity

Question Camera Bump when finishing recentering

Discussion in 'Cinemachine' started by Patrick_Machado_, Jul 15, 2022.

  1. Patrick_Machado_

    Patrick_Machado_

    Joined:
    Feb 1, 2018
    Posts:
    67
    Hey guys we are having an issue in polishment, it happens when the camera is displaced/teleported and we trigger recenter on it, it recenter smoothly but when the recentering movement is about to end it moves abbruptely to the final position causing a tiny but very fast movement which is not very good in terms of polishment,

    I've had run some tests and im sure that its the Cinemachine configuration I just dont know what exaclty it migh be, we are using FreeLook Camera with all set to Hard Look (which i suspect the most) but I cant find a config that I can change and avoid so what could it be?

    Pictures attached

    Thanks
     

    Attached Files:

    • CM1.PNG
      CM1.PNG
      File size:
      21.1 KB
      Views:
      164
    • CM2.PNG
      CM2.PNG
      File size:
      36.7 KB
      Views:
      164
    • CM3.PNG
      CM3.PNG
      File size:
      40.2 KB
      Views:
      163
    • CM4.PNG
      CM4.PNG
      File size:
      26.6 KB
      Views:
      155
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Can you give a little more information?
    • What version of CM are you using?
    • How exactly do you trigger recenter?
    • If you trigger recenter without teleporting, does it still bump at the end?
    • Can you show a video of the problem?
     
  3. Patrick_Machado_

    Patrick_Machado_

    Joined:
    Feb 1, 2018
    Posts:
    67
    Yeah!
    _The CM is Version 2.8.4
    _The game teleport the character in different possitions in 3D (xyz) world pos and then trigger recenter
    _Not it doesn't, it only happens in this case
    _I got youa vide in the link:
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Sorry for the late reply. Thanks for the info.

    I was looking for a player teleport in your video but I didn't see one. Where exactly is the problem? I see a tiny camera snap at the very end, but I didn't notice a teleportation or a recentering of anything, so I'm not sure that this is the problem you are referring to.

    I have 2 questions:
    1. When you teleport the character, do you call CinemachineCore.Instance.OnTargetObjectWarped()?
    2. How exactly do you trigger recenter?
     
  5. Patrick_Machado_

    Patrick_Machado_

    Joined:
    Feb 1, 2018
    Posts:
    67
    Yeah is that tiny snap u can see it better on the second 16 of the video.
    Its just being hard for me to find out what its causing it. If its a collider or a config I dont know.
    1.No, i literally teleport the player and the camera will follow by the CM follow along
    2.It is being triggered by code triggering the Recenter function both on Vertical and Horizontal, codewise it never happens in any other situation but this, sometimes the CM triggers the Horizontal default recenter by its own but its all the same in code because it validates if the camera is in its default position


    Code (CSharp):
    1. IEnumerator RecenterHorizontal()
    2.     {
    3.         //float force = (Time.deltaTime * recenteringHSpeed * dirSignal);
    4.         //if (isRecenteringByTime) { force *= recenteringByTimeSpeed; }
    5.         //        camRig2FolowChar.RotateAround(camRig2FolowChar.position, Vector3.down,
    6.         //                (force * Time.deltaTime * speedHorizontal * 100f));
    7.         if (isRecenteringByTime)
    8.         { camRig2FolowChar.localRotation = Quaternion.Lerp(camRig2FolowChar.localRotation, charTran.localRotation, Time.fixedDeltaTime * recenteringByTimeSpeed); }
    9.         else { camRig2FolowChar.localRotation = Quaternion.Lerp(camRig2FolowChar.localRotation, charTran.localRotation, Time.fixedDeltaTime * recenteringHSpeed); }
    10.  
    11.         yield return new WaitForSeconds(0);
    12.  
    13.         if(Mathf.Abs(verifyDistance(transform, defaultCamPos)) <= distXfromAnchor
    14.             || Input.GetAxisRaw("Horizontal") != 0 ||
    15.             Input.GetAxisRaw("Vertical") != 0)
    16.         {
    17.             StopCoroutine("RecenterHorizontal"); canMoveAround = true; isWaitingToTurn180Again = false;
    18.             resetRecenteringBytime(); resetVarRecenterXbyBtn();
    19.         }
    20.         else { StartCoroutine("RecenterHorizontal"); }
    21.  
    22. //        if (Mathf.Abs(Vector3.Distance(transform.position, defaultCamPos.position)) <= distXfromAnchor)
    23. //        { StopCoroutine("RecenterHorizontal"); canMoveAround = true; isWaitingToTurn180Again = false;
    24. //            /*movementUnichan.UpdateForwardDir();*/ resetRecenteringBytime(); }
    25. //        else { StartCoroutine("RecenterHorizontal"); }
    26.     }
    27.     IEnumerator RecenterVertical()
    28.     {
    29.         float force = Time.deltaTime * recenteringVSpeed;
    30.         if (isRecenteringByTime) { force *= recenteringByTimeSpeed; }
    31.         anchorLookAt.localPosition = Vector3.Lerp(anchorLookAt.localPosition, anchorLookAtDefaultPos.localPosition, force);
    32.             //= new Vector3(anchorLookAt.localPosition.x, Mathf.Lerp(anchorLookAt.localPosition.y, defaultCamHeigh, force), anchorLookAt.localPosition.z);
    33.         yield return new WaitForSeconds(0);
    34.         //if (Mathf.Abs(anchorLookAt.localPosition.y - defaultCamHeigh) < distYfromAnchor)
    35.        
    36.         if (Mathf.Abs(Vector3.Distance(anchorLookAt.localPosition, anchorLookAtDefaultPos.localPosition)) <= distYfromAnchor)
    37.         { StopCoroutine("RecenterVertical"); resetRecenteringBytime(); resetYCanScroll(); }
    38.         else { StartCoroutine("RecenterVertical"); }
    39.     }
    The main recenter methods are those, they movimentates the gameobjects that the camera is told to LookAt(), as if it where an anchor.
    This works pretty fine so I've not much doubts that could be probably another thing causing it,not 100% sure either. When I turn off CineMachine it doesnt snaps.

    Thank you!
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Sorry, but I can't tell for sure what is causing the bump. I don't know what your Body damping settings are in CM. Can you show them?

    You are doing some fancy footwork in your enumerators. I suspect the problem lies there. Why are you using fixedupdate time in there? Lots of room for error.

    If you would like to make a simple test project that reproduces the issue, I can take a look at it.
     
  7. Patrick_Machado_

    Patrick_Machado_

    Joined:
    Feb 1, 2018
    Posts:
    67
    Hey there !

    Yeah the project needed a lot of specific camera work, but basically this error only happens when the CM component is on, and only when stairs transitioning (im suspecting its the height difference between the two positions)

    To reproducoe, AWSD to walk, mouse to movemente the camera, and spacebarr when the stairs are highlighted to start the transition, when it ends you can see the small snap vertically as the video before shows too.

    Maybe using late update instead? Enteresting...
    You can download it here withing 30 days:
    https://easyupload.io/f3axj2

    Thank you for the support!
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thanks but I'm having trouble downloading this. Is there anything you can do to make it smaller? Some things you can try:
    1. Delete the Library folder before uploading. It's huge, and Unity can regenerate it at the destination.
    2. Delete unused assets. I don't need fancy textures and environments - only the specific assets necessary to repro the issue.
    EDIT: nvm, download finally succeeded
     
    Last edited: Aug 17, 2022
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thanks for the upload. I can repro the issue.

    The problem has nothing to do with recentering. It happens because when the cutscene finishes, your character gets displaced a little - its position pops. Because you have set up your FreeLook to have no damping at all, the camera pops along with the character, and you see a little jolt in the background. It happens at the top of the stairs also.

    If I change the FreeLook and add a little damping, the jolt disappears because the damping smooths it out.

    upload_2022-8-18_7-57-20.png

    So, your options are to either fix your code that makes the character jolt, or add some camera damping to hide it. You might consider adding some damping anyway, because IMO the camera looks better with it, but that's obviously your creative choice.
     
  10. Patrick_Machado_

    Patrick_Machado_

    Joined:
    Feb 1, 2018
    Posts:
    67
    Hey yeah that really made it!

    But takes away our control during the cutscene and during the walking because of the camera position update and walking blending camera forward vector with the character velocity vector.

    But yeah guess I'll try programming a system to change those damping variable values from code and make them 1 during the transitions only!

    I really appreciate the help,
    Thank you very much!
     
    Last edited: Aug 24, 2022