Search Unity

Confiner glitching

Discussion in 'Cinemachine' started by nicmarxp, Jan 20, 2020.

  1. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    406
    I have a simple 4 point PolygonCollider2D as a BoundingShape2D for the CinemachineConfiner.
    The camera is set up to follow the player, and in the video you can see the green border as the collider. It works perfectly when inside the shape, but when I move the player outside of the collider, the vcam jumps to different weird positions.

    Also it gets stuck in some positions as I move along the edge. Do you have any what is going on here and how to fix it?

    I notice the issue changes, but still remains when I change the offset of the PolygonCollider2D. As you can see in the start of the video, the arrow shows that the origin of the PolygonCollider2D is close to the middle.

    The level in the background is made of several tilemaps, and each is 32x32 units, and the camera seems to stick to those values somehow, but the issue also happens without the tilemaps.

    Thank you in advance!

     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Thanks for reporting the issue. We are aware of some problems with the CinemachineConfiner. We'll address it in a feature update.
    In the meantime, you can try modifying the CinemachineConfiner.cs script, and modifying the
    ConfineScreenEdges function.
     
    nicmarxp likes this.
  3. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    What you are getting is strange, and should not happen.
    Could you send us a simplified version of the above issue, so we can reproduce and possibly fix the problem? ;)
     
    nicmarxp likes this.
  4. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    406
    Hey, I tried to recreate it, but noticed that it seemed to happen under certain circumstances. I'm generating map chunks, which is run in coroutines, and when each piece is complete, it does this:
    - Find all corners of the map
    - Make a poly and assign it to m_BoundingShape2D of CinemachineConfiner.

    If I wait until all chunks are generated, and then runt that code, it works.

    So I could guess that it could be that the PolygonCollider2D i'm generating is shown correctly, but the actual m_BoundingShape2D is from a point in time when the level wasn't generated completely. However this doesn't explain the weird jumping, but at least it solves it for me at this point.

    Thank you :)
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,723
    You have to call InvalidateCache() (or something like that - I forget exactly) in the confiner if you change the polygon shape. It caches some stuff and if you change the shape you have to tell it. That's why you get the weird results.
     
    nicmarxp likes this.
  6. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    406
    Thanks, that sounds like it would be the issue! I will try that :)