Search Unity

Cinemachine Confiner for 2D

Discussion in 'Cinemachine' started by hippo_san, Oct 16, 2017.

  1. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    18
    I'm using Cinemachine Confiner extension to prevent virtual camera from reaching out 2D boundary. But it seems not work as expected. Here is my step:
    1. create a plane with box collider as large as the scene
    2. drag the plane to Bounding Volume of Cinemachine Confiner

    Please have a look. Thanks.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,394
    It's working for me. I'm using CM 2.1 RC4.
    What behaviour are you expecting, and what are you getting?

    Note that even in a 2D scene, the box collider needs to be a 3D object, whose position is such that the camera will be inside it. So, if the camera is 10m in front of the game plane, then the box collider needs to include the plane where the camera is: either position it at z = -10, or have its Z size big enough to include the z=-10 plane.

    Here is my vcam setting:

    upload_2017-10-16_9-34-25.png

    And here is my collider plane:

    upload_2017-10-16_9-35-38.png
     
  3. hippo_san

    hippo_san

    Joined:
    Oct 29, 2014
    Posts:
    18
    Worked! I guess the reason why the camera beyond the bound is I did not check "Confine to screen edges"...Is it be good if it was by default?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,394
    Yes, good idea.
     
  5. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    172
    Just found this. It was exactly what I was looking for. :)
     
  6. MartinParadis1970

    MartinParadis1970

    Joined:
    Apr 12, 2019
    Posts:
    1
    I just want to share my thoughts on the way the Confiner 2D works, or should works more specifically. I struggled for some time before I realized something : Each time I assign a new PolygonShape2D (for example) to the confiner, I had to call "InvalidatePathCache" method. To me it is not intuitive because the confiner let us know (the client of the API) of its internal "poutine" and it should not work that way. Of course, when I assign a new Shape to the confier, it should invalidate automatically its internal cache, that's the contract I have with the confiner. Suggestion, instead of having a public member m_BoundingShape2D, give us a method or a property, in that case you could invalidate the cache automatically each time a user set a new BoundingShape... That my 2 cents.. :)
     
    Gregoryl likes this.
unityunity