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.

Question How to make Cinemachine camera zoom and rotate when colliding

Discussion in 'Cinemachine' started by Vizen30, Mar 28, 2023.

  1. Vizen30

    Vizen30

    Joined:
    Apr 20, 2021
    Posts:
    5
    Hi everyone, I'm working on a split-screen game and would like some guidance on how to achieve this:
    https://youtu.be/Goa3Pt_iFNI?t=196

    When Cody (player on the right) looks up he has an excellent view of the whole level while still being on screen.

    This is instead what I have right now. GIF LINK
    What I'm currently using is a Cinemachine FreeLook camera with a Cinemachine Collider extension on it.
    If needed I can also share all the settings used on the Cinemachine elements. Maybe the first relevant thing to say is that the "Minimum Distance From Target" on the Cinemachine Collider is set to 0.01.

    What I want to basically do is make the camera get closer to the player if collides with something but at the same time rotate it so the player would have a better view of the upper part of the level.

    What's the best way to achieve it?
    Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,882
    I wouldn't depend on the collider for this. Instead, I would set up the FreeLook's bottom orbit to be really close to the player, below the LookAt spot, so the camera looks up at it, something like this:

    upload_2023-3-29_13-58-54.png

    Also adjust the ScreenY in the composers of the 3 rigs to position the player where you want it in the frame.
     
  3. Vizen30

    Vizen30

    Joined:
    Apr 20, 2021
    Posts:
    5
    Thanks for the answer!!

    That's what I'm doing with the camera for the other player at the moment. The problem in my case is that the character/model for the spider is not "tall" enough to allow me to do so. If I would take your pic as a reference she would be out of sight of the camera.

    I don't know if there's any better solution to that though, that's why I asked here :)
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,882
    If the character is very small then you'll have to do it by adjusting the ScreenY of the bottom rig. If you put it low on the screen, then the camera will be more angled upwards.

    You should also make the camera radius small in the CM Collider, to allow the camera to be as close as possible to the floor.
     
  5. Vizen30

    Vizen30

    Joined:
    Apr 20, 2021
    Posts:
    5
    Thanks for the reply. I did so, now the radius of the camera is 0.5 and we achieved something that is what we were aiming for.

    I have another question though.
    I have now set up a script that changes the camera from one FreeLookCamera to another FreeLookCamera with different rigs but, when that happens, the camera changes but looks up instead. Here's a GIF LINK that shows the behaviour.

    Any idea why this is happening?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,882
    Try enabling this on the FreeLook. Does it help?

    upload_2023-4-11_7-26-11.png
     
  7. Vizen30

    Vizen30

    Joined:
    Apr 20, 2021
    Posts:
    5
    Yes, I already had that set it up but it doesn't fix the problem
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,882
    Are the LookAt and Follow targets at the same point? There is a gotcha in FreeLook: if the LookAt and Follow targets do not correspond to the same point, then InheritPosition can sometimes erroneously put the incoming camera on the bottom rig. The workaround is to create an empty child object in the target, positioned at the desired LookAt point, and use it for both LookAt and Follow targets.
     
  9. Vizen30

    Vizen30

    Joined:
    Apr 20, 2021
    Posts:
    5
    Yes, the LookAt and the Follow object are the same. I don't get why the first transition of the camera works smoothly but the second one doesn't
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,882
    Do you have a nonzero TrackedObjectOffset in the freelook Aim?