Search Unity

Look ahead and player teleportation

Discussion in 'Cinemachine' started by Hindi, Jun 22, 2020.

  1. Hindi

    Hindi

    Joined:
    Apr 14, 2013
    Posts:
    59
    Hello there,

    The look ahead feature doesn't work well with my player teleportation: the farther my teleportation point is, the farther the camera position overshoot.
    I tried to set
    m_LookaheadTime
    to 0 before teleporting, and setting it back to its original value after a second, but it leads to a very weird behavior.

    Is there a way to disable the look ahead feature for a while and re-enable it without any issue?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    1. What version of CM?
    2. How are you doing the teleport?
    3. Can you show your vcam inspector?
     
  3. Hindi

    Hindi

    Joined:
    Apr 14, 2013
    Posts:
    59
    1. Version 2.5.0
    2. It is an instant teleport, I set a new value to Rigidbody2D.position. I excpect to find bugs related to this in the future, but it's a good temporary solution for prototyping.
    3.
     
    gaborkb likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    ok, your problem is that when you instantly teleport your camera target, the vcam thinks that it just moved quickly, so responds by trying to follow it - with damping and lookahead. You need to inform the vcam that it should teleport also.

    The API for this is vcam.OnTargetObjectWarped(). Call that at the same time as you teleport your player. Damping and lookahead will not be calculated for the teleport.

    This post shows a robust way to call it, warping all the vcams that are targeting the player:
    https://forum.unity.com/threads/rep...how-to-avoid-the-popping.514293/#post-3396611
     
    Last edited: Jun 22, 2020
    gaborkb and Hindi like this.
  5. Hindi

    Hindi

    Joined:
    Apr 14, 2013
    Posts:
    59
    What a neat solution! Thanks a lot Gregoryl, it works really well.
     
    gaborkb and Gregoryl like this.
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Looking at your vcam inspector, I find that it's a little strange to have the camera offset extension there. Why don't you instead adjust the Screen Y in the Framing Tansposer?
     
    gaborkb and Hindi like this.
  7. Hindi

    Hindi

    Joined:
    Apr 14, 2013
    Posts:
    59
    Thanks for pointing that out.
    There's no good reason, I was just messing around with this new Cinemachine thing (at least new for me after a while away from Unity) and forgot to remove it. By the way, I'm amazed to see all the new features you added since I used Unity a few years ago. It makes the engine even more attractive than it used to be. Great job!
     
    gaborkb and Gregoryl like this.