Search Unity

Question How to set the active vcam by distance?

Discussion in 'Cinemachine' started by Carwashh, Jul 14, 2021.

  1. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    763
    I'm trying to setup a group of vcams, which swaps the active one by distance. The closest, clearshot, becomes the active camera.

    However, I can't get it working.. CM is setting an active camera as I move away from it and doesn't choose a vcam with the best view. Video of current setup here: https://twitter.com/en9g131/status/1415411650493140994

    For example:

    At the start - this is the best view from the available vcams
    upload_2021-7-14_21-40-32.png

    CM chooses this camera instead
    upload_2021-7-14_21-41-2.png

    I'm using a clear shot, with these settings.
    upload_2021-7-14_21-41-46.png

    and each virtual camera has these settings.
    upload_2021-7-14_21-41-53.png
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    In what way is the ClearShot choosing the wrong camera?

    With the settings you have, and assuming that Vehicle is not on the Default layer and that you cave your colliders set up properly for your scene geometry, I would expect the ClearShot to select, from among the vcams with an unobstructed view of the target, the one whose distance from the target is closest to 2m.
     
  3. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    763
    Assuming the target distance is using Unity units(?) the first image.. the camera is about 30m away.. the second image the camera is about 200m away.

    Maybe I wasn't clear.. the first image was taken by me only having that camera available - Clearshot had no other choices. With all cameras enabled, and the drone in the same place.. Clearshot chooses the camera in the second image. I don't understand why that one gets chosen?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Sorry, but your images are not clear to me at all. I don't know what I'm looking at.
    Are your collider volumes set up correctly?
    You can try putting a breakpoint in CinemachineCollider, where it evaluates the shot quality, and see why it' not giving you what you expect.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Try enabling this, to validate that ClearShot is doing what you think it is:

    upload_2021-7-15_13-9-1.png
     
  6. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    763
    The target is a drone, it hasn't moved. Image 1 shows where the camera I expect to be active is. Image 2 shows what clearshot chooses.

    upload_2021-7-15_18-29-19.png


    I don't hve any collider volumes - I guess that's why it's not working as I expect.

    I think I just confused things by showing what I've attemped already... my question is just: How do I do this?
    (I'm off to look at collider volumes)
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Like I said: your setup should choose the vcam that's closest to 2m from the target. If you don't have any collider volumes that's fine - it just means that for the purposes of shot evaluation the vcams will think that they can see through walls.

    Oh, maybe try this: set the Standby Update mode of all the vcams to "Always".
     
    Last edited: Jul 15, 2021
  8. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    763
    I assumed "Collider volume" was something for Cinemachine I wasn't aware of. All my geomtry have colliders on - never come across these being called collider volumes before, have just seen this term in the Cinemachine docs though.

    The setup I have, does not choose the vcam that's closest to 1m (I've lowered it) from the target.
     
  9. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    763
    I've simplified my scene to learn what's going on and get what I'm after.

    Video: https://twitter.com/i/status/1415759724616814594

    Each coloured cube, on the floor, has a vcam above it. Each vcam is 30m off the ground. Optimal target distance is set to 0.

    What I'm wanting to achieve, the cloest vcam becomes the active vcam.. so here, if it's within the grid for the red cube.. that vcam would be active - but if you look at the video above, the vcam for the blue is most likely to be active. The red one will become active as the target moves away from it into another grid.

    upload_2021-7-15_20-50-7.png
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You can control that - to some extent - with the Optimal Target Distance setting. It won't quite give you what you ask for but I think it will come close. What that setting does is boost the quality of the vcam when the target is in the neighbourhood of the optimal target distance. If the actual target distance is too far away from the optimal distance, there will be no boost, so if it's too far from all the vcams then you won't necessarily get the closest one - so you have to place your vcams with some care.

    For your sample setup, assuming that the square formed by the colored squares is 60m on each side (i.e. adjacent squares are 60m apart), if you set the Optimal Target Distance to 30 it will work nicely.
     
  11. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    763
    Ok, I think I'm starting to get it. Thanks a lot for your help!
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    FYI if you put a CM Collider on each of the vcams (instead of one on the ClearShot) then you can have different optimal distance settings for each of the vcams.
     
    Carwashh likes this.