Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice

Feedback Confine Screen Edges + weird bounding shapes = bad results

Discussion in 'Cinemachine' started by MegamaDev, Jun 1, 2020.

  1. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    68
    My virtual camera is set up with a Confiner component. Its mode is Confine 2D, Confine Screen Edges is on, and its bounding shape looks like this:
    CinemachineConfiner - Bounding Shape.png
    (disclosure: these are all temp graphics from other people's games, namely Chrono Trigger, Undertale, and Deltarune. Just to be clear.)

    This looks simple enough: a big room with a smaller room on the sideLots of games do something very like this: Super Metroid, Mega Man Zero 2, Donkey Kong Country [iirc], Kirby And The Amazing Mirror... The trouble is, Cinemachine's results don't hold up in one way or another--and it's in different ways with or without damping.

    If I leave confiner's damping parameter at 0, the camera will "pop" from one side of an inner corner to the other:
    Corners.gif

    Higher damping values make the corner look better (pictured here is damping=4):
    Corners Damped.gif
    but it also allows me to push the camera past the edge of the box, which is...not acceptable.
    Edges.gif
    It's like, if I'm giving boundaries to the camera, it's because I want the camera to stay in the boundaries*, right? In fact, I think this is the exact behavior I'm trying to counter by even using Confiner2D, given that this drift is somewhat characteristic of the Framing Transposer.

    (*yes I can see outside the bounds in the damped corner example, but I'm not concerned with that because tons of games make that affordance, even with no damping.)


    A solution I might like to see, in this case, would be to have two damping values: one for walls (preferably set in units of allowed pushback), one for corners.


    This isn't nearly the extent of the unpleasant results of Cinemachine Confiner that I've seen, but I have a hunch that most of those problems would go away if I could just use damping. That said, damping lends the camera an aesthetic that I'd like to be able to opt out of, so I'll keep you posted, just in case the problems I find can be fixed.


    I've heard Cinemachine is a fantastic, top-level tool, and it makes me sad that the 2D camera-boundary system hasn't worked for me as well as I've heard the 3D portion works (my work has been almost exclusively 2D up to this point, so I've not used most of the 3D).
    What I've presented here doesn't even begin to cover what I'd like Confiner 2D to do (will elaborate if desired), but I really hope it's helpful.


    Finally, because this may be relevant: damping=0 makes exactly fitting into corners a bit weird, it seems. Watch as the camera pops back and forth:
    NoDamp Pops.gif
    Small thing, but it's bugging me so, so bad. It's weird, man!
     
    Last edited: Jun 2, 2020
    marc_tanenbaum likes this.
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    663
    We are working on a more robust Confiner system. It is not trivial, but we have some great results already. The problem seems simple, but there are a lot of things to consider. Your concerns are in the list of things we'd like to address in this robust version. ;)

    Noted.

    We would be very happy if you'd share your thoughts! We are eager to give the love this feature deserves :)
     
    Gregoryl and marc_tanenbaum like this.
  3. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    68
    Nice. Good to hear~

    Having tried myself tried to build a Confiner-like system (that didn't even use polygons to define its boundaries, only AABBs!), I can totally respect this. Honestly I have respect for your managing to get this much working!

    Alright, will do....

    What I'd like to see is roughly as follows: if the camera is moving toward a wall with a suitably-sized tunnel in it, let the camera phase through the corner in order to end up in the tunnel, then gradually push it back into bounds.

    So given a confiner setup such as this (yellow = confiner's outer edge):
    Theoretical Boundary.png
    the camera's movement is roughly this (green = path of camera transform, dark pink = path of camera edges):
    Theoretical Boundary Displacement.png
    Observe how the camera's movement gradually shifts from the old Y to the new Y, phasing through the corner as it goes. A vertical path would do an equivalent movement if it were to clip the corner of a vertical tunnel, for example.

    This movement would not be dependent on any form of damping. Its speed, optimally, could be set to at least these modes: Fixed Rate mode, where the camera always moves at a certain speed (or one x-speed, one y-speed); Fixed Time mode, where the camera always takes the same amount of time. Damping could certainly be applied, of course, to the movement's start & end; would be cool if, additionally, Fixed Time mode could follow a trajectory defined by an Animation Curve.

    For bonus points, the camera would be able to handle tunnels smaller than the camera's own dimensions, possibly up to arbitrarily tight tunnels. In this case, the camera will try to balance the bad space, giving favor to whatever solution puts the target closest to expected, possibly biased in favor of hanging out in whatever tunnel is closest to the target if multiple tunnels are on screen (now that'd be cool--multiple tunnels support!).
    ...Huh. This bit might work for the entire confiner system on its own. It could be helpful to have the phase-through-corners-if-there's-a-tunnel rule too, though.
    As an additional alternate behavior, the camera might zoom in to fit within the tunnel. This would probably follow the same transition logic as the back-into-bounds push. This would probably require a match-width-or height slider a la Canvas Scaler...among other controls?


    ...Whew. I told you I'm verbose :) Hopefully this is any help, and hopefully none of this is dependent on anything that shouldn't be part of Cinemachine (facing direction, character collision info), since that'd be pretty hard to require in a camera system meant to work for everyone... ¯\_(ツ)_/¯

    Also important to note: I largely assume any given camera bounding shape to be decomposable into axis-aligned bounding boxes, which is almost definitely a personal idiosyncrasy and not going to hold in the real world. Do take this into account, because there's almost certainly parts of my description which I've not generalized to non-square bounding shapes.
     
    gaborkb likes this.
unityunity