Search Unity

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:
    193
    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:
    2,501
    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:
    2,501
    Can you show me a picture of your vcam inspector?
     
  4. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    193
    @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:
    193
    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:
    193
    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:
    2,501
    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:
    193
    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:
    2,501
    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:
    193
    Latest I found on the asset store, 2.1.10
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

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

    agiro

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

    jonathangutman

    Joined:
    Dec 6, 2016
    Posts:
    5
    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:
    193
    @Gregoryl Wouldn't want to rush you but approximately when to expect a patch?
     
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    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:
    193
    That's actually pretty quick. Keep up the good work :D
     
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    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:
    2,501
    PMing you with the patch
     
  19. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    193
    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:
    2,501
    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);
     
    Damooon and Deeeds like 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:
    2,501
    well... you could PM me and I could send you a patch
     
  24. EwigeDreamer

    EwigeDreamer

    Joined:
    Sep 29, 2017
    Posts:
    3
    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:
    2,501
    @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:
    193
    @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:
    2,501
    nope, but thanks for the flattering supposition
     
  28. MrMuh

    MrMuh

    Joined:
    Jan 6, 2019
    Posts:
    2
    Hi!
    I am currently trying to implement a floating origin reset and everything looks very seamless when I use the OnTargetObjectWarped API - but when I enable the Cinemachine Confiner extension it starts to get choppy again. I tried to call OnTargetObjectWarped on the Confiner script but it doesn't fix the issue.
    Code (CSharp):
    1. GetComponent<CinemachineConfiner>().OnTargetObjectWarped(player.transform, posDelta);
    @Confiner setup: I am not sure if it is important but I want to constrain the camera movement to the y axis and therefore I created a collider polygon with the following points:
    Code (CSharp):
    1.             Camera.main.ViewportToWorldPoint(new Vector3(0f, 0f, 0)),
    2.             Camera.main.ViewportToWorldPoint(new Vector3(1f, 0f, 0)),
    3.             Camera.main.ViewportToWorldPoint(new Vector3(1f, 100f, 0)),
    4.             Camera.main.ViewportToWorldPoint(new Vector3(0f, 100f, 0))
    Do you have an idea how I could fix this problem?
     
  29. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    @MrMuh You don't need the call OnTargetObjectWarped on the confiner, that will be done automatically by the vcam.
    Can you elaborate a little more on what is not working? Maybe put together a little example that shows the problem?
     
  30. MrMuh

    MrMuh

    Joined:
    Jan 6, 2019
    Posts:
    2
    @Gregoryl thank you very much for the feedback! While preparing my example I found the issue :D The issue was that I moved the camera to a point which moves the camera into the collider which is used by the confiner. The vcam got moved out of the collider polygon which caused this "choppy" movement. So in the end everything works perfectly fine :)

    Thx for the support!
     
    Gregoryl likes this.
  31. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    65
    Hi @Gregoryl, many thanks for this update. It is great!

    But imagine situation when you have base scene with the camera and vcam, you loading new scene in "additive" mode, spawn your character, move camera with OnTargetObjectWarped, set m_BoundingShape2D in Confiner. You getting to the portal, load new scene in "additive" mode, move character, move camera with OnTargetObjectWarped, and put new m_BoundingShape2D in Confiner.

    As result: if vcam collides with new bounds it jumps out of the bounds, move character deeper - vcam appears inside the bounds. Go to the edge - it jumps out again)

    I make workaround by RemoveExtension(Confin)+Destroy(Confin)+AddComponent(Confin)+AddExtension(Confin). And now I can load scene, warp my character and put new Confin.

    I assume there is some defect, as extensions know about warp, but do not handle it properly.
     
  32. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    You need to call confiner.InvalidatePathCache() when you change the collider shape.
     
    vhman likes this.
  33. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    65
    Yes, that works.

    Sorry, that is clearly pointed in documentation.
    Thanks!