Search Unity

Teleport Player seamlessly with Cinemachine

Discussion in 'Cinemachine' started by IvayloDev, May 19, 2020.

  1. IvayloDev

    IvayloDev

    Joined:
    Apr 20, 2015
    Posts:
    23
    Hello, I need to teleport my player which is followed by a cinemachine camera( 2 actually, because we have a camera for the aim and are controlled by camera mixer).

    I have attempted many approached to make it seemless, but there is always a noticeable transition. I tried to lerp all the camera properties before teleporting(for example the look ahead time), but still the problem persists.

    Has anyone dealt with this problem before and if so, what is the best solution to this problem,

    Thanks
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
  3. IvayloDev

    IvayloDev

    Joined:
    Apr 20, 2015
    Posts:
    23
  4. IvayloDev

    IvayloDev

    Joined:
    Apr 20, 2015
    Posts:
    23
    Ok, so the camera is teleporting ok, but for some reason there is a visible transition. For example, the look ahead time is somehow not catching up after I teleport the player.

    Here is my code:


    GameObject player = PlayersSystem.Instance.GetPlayer(0).gameObject;

    Vector3 deltaPos = _newPosition - player.transform.position;

    PlayersSystem.Instance.GetPlayer(0).gameObject.transform.position = _newPosition;

    //Update internal state for all VCams
    int numVcams = CinemachineCore.Instance.VirtualCameraCount;

    for (int i = 0; i < numVcams; ++i)
    {
    CinemachineCore.Instance.GetVirtualCamera(i).OnTargetObjectWarped(CinemachineCore.Instance.GetVirtualCamera(i).Follow, deltaPos);
    }

    I even tried to add a yield return new WaitForEndOfFrame(); before I call OnTargetWarped and after teleporting but still a transition is visible.
     
    Last edited: May 20, 2020
  5. IvayloDev

    IvayloDev

    Joined:
    Apr 20, 2015
    Posts:
    23