Search Unity

Possible incorrect aspect ratio for Cinemachine Confiner

Discussion in 'Cinemachine' started by 02leeken, Oct 31, 2018.

  1. 02leeken

    02leeken

    Joined:
    Jan 10, 2014
    Posts:
    3
    Hello,

    We've recently updated to the latest version of Cinemachine (2.2.7) and noticed that some behaviour that was working previously is no longer working.

    We have a virtual camera that is following the player, with a 2D confiner that uses a collider that is the exact same size as the camera itself. The goal was to stop camera movement whenever the player entered a room of that size, and it seemed to work properly prior to the update. Now however, the upper boundary no longer constrains the camera (i.e. the camera cannot move left, right, or down, but is able to move upward).

    After digging a bit deeper, I think there's a potential issue with CameraState.Lens.Aspect. Our camera's aspect ratio is 16:9, and instead of getting the expected 1.77777778 from the CameraState.Lens.Aspect, it's returning 1.778831 (as seen below), which is 16:8.99. This causes the camera bounds to be detected as slightly larger than the confiner bounds, which is a problem. Casting dy and dx to Ints to drop the decimals fixes it, but is kind of a hacky fix (and doesn't work if you're using non-whole number aspect ratios).

    confinescreenedges.png

    We might have screwed up a project setting somewhere to cause this, but I thought I'd bring it up in case it is a bug. I should also mention we updated Unity from 2018.1.5 to 2018.2.12 at the same time we updated Cinemachine, so it might be a Unity bug instead. I don't know how state.Lens.Aspect gets the aspect ratio.

    Thanks,

    Kenny
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thanks Kenny for reporting that. In fact the lens aspect calculation has changed since the introduction of Physical Cameras in 2018.2, and clearly the precision is a little different.

    Probably the best fix would be to give the confiner a little slop when confining, so that it's more forgiving of such imprecision. It's a bit naive at the moment. Another workaround would be for you to grow your bounding box just a tiny bit - would improve performance too, since a little too small is the worst case scenario.
     
  3. 02leeken

    02leeken

    Joined:
    Jan 10, 2014
    Posts:
    3
    Thanks for the response.

    Our first solution was to try making the confiner box a little bit bigger, but the result was a very slight shift in the camera whenever you moved around. Since this only happens when the confiner and camera bounds are the same size, we're also thinking of just disabling camera movement entirely for those rooms.