Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Reposition target and camera runtime - how to avoid the "popping"?

Discussion in 'Cinemachine' started by agiro, Jan 25, 2018.

  1. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    I'm in the making of a simple endless game where I use Cinemachine.
    My problem is that - as endless games require - I occasionally revert the position of the player and the environment to avoid going to high float values.
    I do have damping on my camera's X which causes a noticeable "popping" in the otherwise seamless revert.
    How could I avoid this popping?
    Here's what I code, pretty simple:

    Code (CSharp):
    1. playerTransform.position -= delta;
    2. Camera.main.transform.position -= delta;
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    Oh boy, I don't think we cover that case! Let me think more about it and get back to you.
     
    syscrusher likes this.
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    Can you show me a picture of your vcam inspector?
     
  4. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    @Gregoryl Okay, thanks. Btw cinemachine solves a lot of scripting for a decent cam movement for a project so thanks for adding it in :)
     
  5. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    upload_2018-1-25_16-31-14.png

    upload_2018-1-25_16-31-31.png
     

    Attached Files:

  6. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    Note I messed around with the cam a bit after the post so it isn't exactly the same but the popping effects remains.
    @Gregoryl Did I post the info you needed?
     
    Last edited: Jan 25, 2018
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    Yes, the popping effect will remain so long as you have damping. You can't just poke the Unity Camera's position, because it's 100% controlled by the vcam, so your value will be immediately overwritten.

    We need to add an API call in the vcam to apply the delta to both the camera and the damping data. There's no other way to get it to work. I'll see if I can throw together a patch for you. Is this your only vcam?
     
    Deeeds likes this.
  8. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    Yep, only Vcam. How to make that API call? Edit: and only camera in the scene. Edit again, the "we" in "we need to apply...." refers to you at unity, or you and I? :D sorry, not a native speaker, got confused xd.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    I need to give you a patch for CM that adds the API call. What version of CM are you using?
     
  10. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    Latest I found on the asset store, 2.1.10
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    ok, thanks. Stay tuned, I'll get something to you asap.
     
  12. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    Great thanks :D in the meantime I build other parts of the game.
     
  13. jonathangutman

    jonathangutman

    Joined:
    Dec 6, 2016
    Posts:
    2
    We've had similar issues where we needed to position and rotate the camera because of seamless portals connecting with other parts of the level. Have not been able to get it working if there is an active blend occuring during the teleportation or if recentering is enabled on the active vcam.
     
  14. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    @Gregoryl Wouldn't want to rush you but approximately when to expect a patch?
     
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    It's a little tricky, and there are a few things to check. Also there are other fires around here :). Probably today or tomorrow.
     
  16. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    That's actually pretty quick. Keep up the good work :D
     
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    I fave a fix for the repositioning of a camera, but rotation is a little trickier. Can you give a little more info about your situation? A sample project would be great.
     
  18. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    PMing you with the patch
     
  19. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    Sorry took apart some stuff in the project :( Right now it doesn't have the "teleport back" feature. However, It doesn't rotate the camera, it's fix always. It only tracks the movement of the player, the rotation of the cam is the same always.
     
  20. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    29
    Any updates on this? I'm in the same boat as agiro. I recenter the whole world regularly.
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    If you're on Unity 2018, you can grab the latest CM release candidate from the package manager. In it, there is a new API call: vcam.OnTargetObjectWarped. After repositioning your target, you would call it as follows (transform is the thing that got moved):
    Code (CSharp):
    1.             // Inform any vcams that might be tracking this target
    2.             int numVcams = CinemachineCore.Instance.VirtualCameraCount;
    3.             for (int i = 0; i < numVcams; ++i)
    4.                 CinemachineCore.Instance.GetVirtualCamera(i).OnTargetObjectWarped(
    5.                     transform, posDelta);
     
    Deeeds likes this.
  22. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    29
    Thanks. Any tips if my project isn't in a good place to move past 2017 yet?
     
  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    well... you could PM me and I could send you a patch
     
  24. EwigeDreamer

    EwigeDreamer

    Joined:
    Sep 29, 2017
    Posts:
    1
    Hello) @Gregoryl , i have a similar project with a similar problem: airplane simulator in very big world. I must teleport this airplane every 1km to the center of coordinates together with other objects in the scene. Every time I give all transforms in scene a Vector3 offset... (including a CMbrain and vcam, but it does not work)
    What do I need to do to make the camera teleport without jerking? (i use Unity 2017.1.2p4)
    fffffffffffffffffffffaaa.PNG
     
  25. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    @EwigeDreamer If you upgrade to CM 2.1.12 there is an API call to support exactly this: vcam.OnTargetObjectWarped(). Are you in a position to upgrade? You will need Unity 2018.
     
    metroidsnes likes this.
  26. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    192
    @Gregoryl Just out of curiosity. On gamedev.stackexchange there is a DMGregory named super helpful user. Ain't he you?
     
  27. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,548
    nope, but thanks for the flattering supposition