Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question How to make a cam follow the player but also frame another GO (zooming in and out)

Discussion in 'Cinemachine' started by angiemon, Mar 12, 2024.

  1. angiemon

    angiemon

    Joined:
    Mar 26, 2018
    Posts:
    38
    I hope that's a good title :)

    So we have this topdown arena level, where the camera is a framing composer following the player and there is a cam confiner so when at the border of the arena it doesn't zoom too far out to irrelevant parts,
    this works awesome so far, now we have a boss level where I still want the camera to do the same, but also sort of frame the boss, as in if the boss would leave the image, to kind of "zoom" out and show a bigger image of the map.

    I did a copy of the first cam, then adjusted the camera distance (made it bigger), and it also needed its own confiner to propery.. confine :) (not show unecessary parts but also don't cut off too early)

    I've tried various things, currently I did a mixed camera where I added both cams and when I change the values the interpolation looks nice. Now how to I best add the "frame boss" functionality?

    Or is there another, better way of achieving what I want to do?

    Love cinemachine but it gets overwhelming fast with all the options (which is great that they are there, but still overwhelming )

    Hopefully that makes sense, thanks guys! :)
     
    Last edited: Mar 12, 2024
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,829
    Can you show some pictures? I'd like to see the vcam inspector, and also an image of the game view for the situation in question.
     
  3. angiemon

    angiemon

    Joined:
    Mar 26, 2018
    Posts:
    38
    Hi, thanks for the fast answer!
    Sure, here you go:

    So this is the main cam we've been using so far, no idea if this is the best way to approach it, but so far it has worked out exactly as we wanted :)

    This is how it looks like:
    MainCamSettingsAndPreview.png

    This is the new Zoomed Out cam, pretty similar to the other one (more distance and has it's own confiner):
    ZoomedOutCamSettings&Preview.png

    This is a litte comparison, not perfect yet and needs more tweaking, but I hope this visualizes what I have in mind :)
    (left one is with the NPC and more zoomed out. so the idea is to smoothly transition between both cams according to where the player and NPC are. so when they are next to each other it's 100% main cam and maximum zoomed in, when they are at the opposite side of the map maximum zoomed out etc :)

    CameraComparions.png

    Haven't done much else, I just created a mixed camera and added both cams and just manually tweaked the available values and the interpolation looked awesome and smooth

    Hope this answered your questions :) Thanks!
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,829
    What version of Unity are you using?
    I ask because if it's 2022.3 or above, you should consider upgrading to CM3.

    Have you tried using a CinemachineTargetGroup and adding your player + the NPC to the group? If you use the group as the camera target, the Framing Transposer can be configured to keep the group framed (by zooming or dollying, or some combo of both).
     
  5. angiemon

    angiemon

    Joined:
    Mar 26, 2018
    Posts:
    38
    we‘re using 2021.something but will probably upgrade to 2022.3 LTS :)

    is there another feature?
    I tried using the target group but it didn’t have desired effects and behaved weirdly. Does it work differently in CM3?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,829
    Pretty much the same in CM3. Can you elaborate on "weirdly"? What did it do vs what you wanted it to do? Possibly you didn't set it up right.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,829
    Did you try something like this (see attached scene)?
    • Play the scene
    • WASD to move the player
    • To toggle between group and player vcams, change the vcam priorities in the inspector.
     

    Attached Files:

  8. angiemon

    angiemon

    Joined:
    Mar 26, 2018
    Posts:
    38
    Hello!! Thanks for all your answers and taking the time to do this!

    That is not only possibly, more like probably ;) I tweaked around a bit yesterday and it worked better but then I got lost in "Yay, now just a little tweak and it's PERFECT... F***, now this needs tweaking too... now this doesn't work how I'd like it too" for like 3484847 times until I gave up :)

    Soooo the scene you sent pretty much sums up what I want! I just copied some settings to my scene and I like it better already, so thanks for that! :)

    I've been thinking about it a bunch now and I think my main issue now remaining is that I'd need two different confiners according to cam distance.

    Example:
    This is the confiner that works great for when they are far apart. Sadly, when they are close and at the border of the map it zooms too far out
    ConfinerGood4FarAway.jpg

    If I change the confiner to cut away the unecessary parts, I can't in this example see the player anymore :(
    ConfinerGood4Closeup.jpg

    This is why I also tried the mixed cam thing with two cams with fixed distances and each their own confiner,
    where I manually tweaked the values and thought the interpolation looks nice.

    Hope this made sense, do you have advice on how to best approach this?

    Thanks again! :)
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,829
    I think that it might be difficult at this angle to have a camera that can see the entire arena, including both front corners, without zooming too much. Have you considered adding another camera at a different angle that sees the entire board? You can switch to that camera when the others have trouble seeing both players.