Search Unity

Question Cinemachine Target Group not showing one of the characters that it is following.

Discussion in 'Cinemachine' started by CodeFixer, Dec 29, 2022.

  1. CodeFixer

    CodeFixer

    Joined:
    Apr 28, 2022
    Posts:
    13
    Hi ! I am experiencing this issue with the target group: I have a terrain 370 by 370 wide ( rather small )
    and 2 characters that the camera must always show. Everything is fine until the two character are almost on the opposite corners of the terrain's diagonal. At that point only one of them is shown. Moreover ( seldom but it happens ) sometimes the camera has odd movements such as showing neither of the 2 characters or even going underground for few seconds. Can an expert help me pls ? Thanx
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Could you show some images of your setup: inspectors of the target group, CinemachineVirtualCameras, and the GroupFramingSettings?
    If you select your CinemachineVirtualCamera in the Hierarchy, then what do you see in the scene view when the odd movements happen or when only one of the objects is shown? There should be some box-like gizmos drawn that indicate the size of the TargetGroup.
     
    Last edited: Dec 31, 2022
  3. CodeFixer

    CodeFixer

    Joined:
    Apr 28, 2022
    Posts:
    13
    Hi ! Thanks for the help. Much appreciated !
    Sorry for the delay in my answer but I spent that time trying to better understand the situation.
    The 2 characters are added to the target group at runtime and this part looks to be without problems.The target group has its default settings.
    I also checked the box you both write about and it is always existent.
    When Unity is running the problem is that at least one character goes out of view if it travels far enough, even bringing the FOV to 200 in the Aim section. I attach the requested screenshots. It is a project that I am doing to learn something more and probably I did something outside my ability.
    Below you can find 3 screenshot. The 3rd one should be at the place of the 2nd and vice-versa

    Brain on normal camera.png CM vcam1 inspector ( bottom ).png CM vcam1 inspector ( top ).png

    Brain on normal camera.png CM vcam1 inspector ( bottom ).png CM vcam1 inspector ( top ).png
     
    Last edited: Dec 31, 2022
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    When the the objects move far apart and only one of them is framed, what is the FOV value on your VirtualCamera? Is it 60?

    If yes, then this means that the group framing algorithm has reach its maximum FOV value set by you:
    FOVRange.png


    If this is not the case, then disable CinemachineCollider on your VirtualCamera. Is the result still the same?
     
  5. CodeFixer

    CodeFixer

    Joined:
    Apr 28, 2022
    Posts:
    13
    Hello gaborkb,
    I brough both the maximum FOV and the Vertical FOV to 179 ( the maximum allowed by Unity ). When Cinemachine 'loses' one of the 2 players the real FOV ( the FOV shown in the normal Main Camera inspector ) is at about 70-80. For some time it also reached about 100.
    At first I also tried with the Cinemachine Collider on and then disabled it to avoid any possible negative influence. Either way the situation remains the same: one of the 2 characters gets lost by the camera.
    I also made few tests with reduced terrains: if they are not larger than 200 x 200, the target group works well.
     
  6. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I could not reproduce it on my side.

    Can you send me a repro project?
    Or can you send me an image of the scene view while the CinemachineVirtualCamera is selected? It should look something like this:
    Screen Shot 2023-01-02 at 5.41.45 AM.png
     
  7. CodeFixer

    CodeFixer

    Joined:
    Apr 28, 2022
    Posts:
    13
    Hi !
    Here is a sample project that I have put together to show you the problem without having other things interfere. This is the best I have been able to put together with Cinemachine's target group.
    The blue sphere is the player. The red one is the other character that must be seen from the camera.
    You can move the blue sphere with WASD ( S & D are to rotate it ). If you send it to the far right or very far forward, you will see that Cinemachine loses the red sphere. How would you set this ?
    Some other questions: I am also unable to raise the camera, how can I do this ? The Body Offset y does not move anything ( in this case ).
    The camera also remains at the same place forever: how can I make it stay, for example, near the middle of the terrain ?
     

    Attached Files:

  8. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I could reproduce the issue with your scene, thank you! ;)
    We'll take a look to see what causes it. I expect it to be a precision issue because it is a perspective camera, and FramingTransposer was designed for orthographic. But it should work with perspective nevertheless.

    However, I think a different setup would work better in your case.
    If you'd like to have a stationary camera, then create a CinemachineVirtualCamera with no Body behaviour. Set Aim to GroupComposer. Set the LookAt target to your TargetGroup.
    With this setup only the rotation of the camera is controlled by Cinemachine, the position is not. You can move the camera by its transform in the scene view.

    Could you describe the behaviour you'd like to achieve?
    In your current setup the camera does not move. Is this what you'd like? If yes, then the above solution using GroupComposer is the way I would set it up.

    I would use Transposer or 3rdPersonFollow in Body and GroupComposer in Aim. You would have easy control over the camera's relative position to the target group (including height) with this Body setup.

    You can also give more weight to your targets in the target group, if you'd like to prioritize their visibility. Though, I don't think that's the case here.
     
    Last edited: Jan 4, 2023
  9. CodeFixer

    CodeFixer

    Joined:
    Apr 28, 2022
    Posts:
    13
    Hi,
    I agree that a target group cinemachine is not the best set up for a large terrain but in reality my aim in doing all of this
    was to learn more about Cinemachine ( this is a test scene, I do not have time to make a game ).

    After the explanation, the good news: after reading your last reply now everything works ! ( THANK YOU !! )
    Last, last 2 question2: in this scene I can not implement a Cinemachine Collider with a Target Group. I send you a revised tiny project.

    Now the Target Group works but often the view is occluded by the walls. And now the question is this: is it possible to have a Virtual Camera intelligent enough to change the side of the square where it is now in order to get a better view of the 2 players ?
    And, anyway, how would you solve this problem ?
     
    gaborkb likes this.
  10. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Yes, there is: CinemachineClearShot. Have a look at our Clearshot sample scene (you can get our samples from the Package Manager -> Cinemachine -> Samples).

    Create a CinemachineClearShot by right-clicking in the Hierarchy -> Cinemachine -> Clearshot Camera.
    Then create CinemachineVirtualCameras on each side of the square. Add these to Clearshot as children. Then attach a CinemachineCollider/CinemachineDeoccluder to the Clearshot. Clearshot will choose a vcam that has clear sight of its targets (e.g. view is not occluded by the walls) and has the highest priority if more vcams have a clear shot.

    Clearshot docs: https://docs.unity3d.com/Packages/c.../manual/CinemachineClearShot.html?q=clearshot
     
    Last edited: Jan 8, 2023
  11. CodeFixer

    CodeFixer

    Joined:
    Apr 28, 2022
    Posts:
    13
    Great ! Thanks a lot ! Much appreciated !