Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Making a ClearShot Camera have all it's children use Group Composer Aim on a TargetGroup

Discussion in 'Cinemachine' started by l337feet, May 31, 2023.

  1. l337feet

    l337feet

    Joined:
    May 18, 2019
    Posts:
    3
    Hey all!

    I'm trying to have a camera system like in "The Last of Us" when the player melee attacks


    Basically, they have a Clearshot camera setup that aims at the middle point between the player's face and the enemy's face and keeps both characters in shot.

    To me, this sounds like a perfect use of the Group Composer aim setting!

    However, I can't seem to get the two playing nicely together out the box. I recognise I may have to do some custom code for the Cinemachine system, but as a complete n00b I wouldn't know where to start.

    Does anyone have any experience with this and would be able to help?
    Thank you in advance for your time.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    What is the specific problem you are having? Just set each child camera to have a group composer in Aim, looking at a group.

    One issue I can see here is that the child cameras compute shot quality by doing a raycast to the LookAt target and checking if there is something blocking it. If the LookAt target is a group, then the raycast will be to the group center, and not to any specific group member. Maybe that's good enough for your purposes, maybe not.

    If not, then it's possible for you to write your own shot quality evaluation extension to override the one that gets computed by default. In CM3 it's even better, you can turn off the default quality evaluation and provide your own.
     
  3. l337feet

    l337feet

    Joined:
    May 18, 2019
    Posts:
    3
    Thanks for the response!

    When the target group is formed dynamically, I don't know how to set the clearshot's (children's) look at target to that group.

    The player sends a raycast to the enemy, they form a group together and then I need to pass that to the camera, but the clearshot camera doesn't accept it as a look at target and I dread to think I have to cycle through every child camera.

    Is there some standard way it is done?

    CM3 just really seems amazing. The whole thing is absolutely incredible and has really just cut out so much work in general and it just keeps getting better and better.
    Cheers!
     
    Gregoryl likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    There should be no problem assigning a TargetGroup as a LookAt target. You can assign anything with a transform (from script, use vcam.LookAt = group.transform).

    You can either set the LookAt in each relevant child camera, or set it in the ClearShot. If you do the latter, then it will serve as the default LookAt target for the children. If you set any child's LookAt to non-null, it will override the ClearShot's default. This is useful when you want to make a ClearShot with heterogeneous children.
     
  5. l337feet

    l337feet

    Joined:
    May 18, 2019
    Posts:
    3
    Oh nooo.

    So it's actually much simpler than I'm making it (or maybe I'm just a little sleep deprived)

    So you're saying I can literally:

    cinemachineClearShot.LookAt = targetGroup.transform

    And that automatically keeps all the transforms in the group composer?

    Thanks so much! Please excuse my ignorance: I didn't understand that the transform of a target group is always its center, even though it seems obvious in retrospect.

    Thank you again.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Yes, a target group is just a way to make a collection of things look like one thing so the cameras can target it.