Search Unity

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

Question How to smoothly slow down virtual camera before hitting a confiner

Discussion in 'Cinemachine' started by ido100ido, Aug 25, 2020.

  1. ido100ido

    ido100ido

    Joined:
    Jun 7, 2020
    Posts:
    8
    I am building a platformer game and I am working on the general camera movement right now. I am using Cinemachines with confiners, In order to confine the camera from moving beyond boundaries when the player is near a wall.

    However, I don't want the confiners to be absolute and stop the camera right away. I am interested in a little slow down of the camera before hitting the confiner (like celeste and hollow knight).

    I could use damping in the Confiner component, however the damping is pushing the camera back from the confiner after "absorbing" it to it's maximum.

    Does anyone have any Idea how to create this feature? I have spent my whole day trying to figure it out...:confused:
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    We'll add it to our feature request list.

    What you could try in the meantime is to add a second collider, that is smaller then your confiner's collider. Detect when the camera hits this. You know when the camera hits this second collider that you are close to the boundary and should start damping.
     
    Last edited: Aug 25, 2020
  3. ido100ido

    ido100ido

    Joined:
    Jun 7, 2020
    Posts:
    8
    Wow very nice! I will wait for this feature to be added in a newer cinemachine version then. I will try to add a substitution code for the meantime as well.
    Thanks for saving me again;)
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I was checking Celeste and Hollow Knight and did not see this feature there. I had the feeling that they have something like the damping in Confiner. Not entirely sure though.

    Could you send some video clips of the exact behaviour in Celeste or Hollow Knight?
     
  5. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    106
  6. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    106
    Not holding my breath, but still interested in this feature.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    You're in luck, this feature is implemented in CM3.
     
    DanielThomas likes this.
  8. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    106
    Very nice! I upgraded to CM3 today and it went smoothly and it looks so much easier to work with.
    If I could give some feedback on the Confiner slowing functionality:

    ------

    It works great in most cases, but in some cases, it's a bit simplistic to just slow down the current direction it's going in. For example a top-down game:
    - You get close to a wall walking left, but then change to walk up-left, There is a jump in speed of the slowdown since the distance is now greater because of the diagonal movement.
    - When close to a corner and walking in random directions, the slowdown can get a bit crazy because of the frequent changes of direction, and with that, the distance changes frequently.

    I tweaked the functionality to check all 4 directions (doing a top-down game, so skipping depth) and just use the lowest for each axis. This seems to work well, and as a bonus moving away also was soft.

    ------

    I'm not sure, but it seems like the slowing down is framerate-dependent. I got significantly longer/smoother slowdowns when I tried with low fps.

    ------

    Speaking of the confiner3D, it would be great if it would support confining the camera edges/frustum. I know it was suggested before but it's a bit tricky with perspective cameras. But could it not work by allowing for setting a distance on the frustum that would be confined? (also please check if it's an orto camera)
    Again, I've already added this myself - I think I found an old script in the forums that did this and so far I can't see any downsides (been using the script for 2+ years)

    Thanks!
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Thanks for the great feedback. We will record it and consider it in upcoming iterations of the feature.