Search Unity

Transposer offset modified dependent on size of target collider

Discussion in 'Cinemachine' started by TreborJones, Apr 26, 2018.

  1. TreborJones

    TreborJones

    Joined:
    Feb 5, 2015
    Posts:
    18
    Hi folks, I'm trying to use one camera setup for a large number of possible units/targets and wondered if there's an easy way to offset the transposer relative to the size of the target objects collider size.

    I've had a quick dig but not 100% sure where to start looking!

    Cheers for any help/direction.

    Bob.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,718
    You could certainly write a little script that you add to the vcam that updates the transposer offset size based on the target collider size, but that might not be the best way.

    For multiple targets, consider adding them to a CinemachineTargetGroup, and using the Group Composer or the Framing Transposer in the vcam. Those components will query the group for the total group size and dynamically position the camera in order to frame the whole thing.

    You should also consider having multiple vcams, each set up to handle a specific situation. Enable the appropriate one for the current game situation, and the Unity Camera will blend beautifully between them. Remember the #1 rule of Cinemachine: don't try to do it all with one vcam.
     
    Last edited: Apr 26, 2018
  3. TreborJones

    TreborJones

    Joined:
    Feb 5, 2015
    Posts:
    18
    Its always a single target, a car. The car varies in size but not to any great extent, it's more that there are 30- 40 of them and I was hoping I could avoid a different setup for each one.

    I'm not an engineer, but someone on my team had tried adding the offset in code but it's a bit of a pain because it prevents me from using the play saving functionality that I've come to love so much! :) I just wanted to double check there wasn't something within cinemachine that dealt with this already, I'll keep working with him to figure it out. Thanks for your help though.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,718
    So you want to create multiple vcams, each with a different (but fixed) offset depending on target size? Sounds like you're going about it the right way.

    If your custom script is dynamically updating the offset based on its own parameters (plus target collider size), then you can ask your engineer to simply add the [SaveDuringPlay] attribute to the custom behaviour, and then SaveDuringPlay will work with it too.
     
  5. TreborJones

    TreborJones

    Joined:
    Feb 5, 2015
    Posts:
    18
    I guess what I'm hoping for is a chase cam setup in a single Vcam with standardised follow and tracked offset values. Then an additive target collider based offset value that scales depending on the size of said collider.

    I'll talk to the engineer about a custom behaviour with the [SaveDuringPlay] attribute. Cheers again!