Search Unity

Using Target Group with Trigger Action

Discussion in 'Cinemachine' started by falsevac, Jan 24, 2020.

  1. falsevac

    falsevac

    Joined:
    Mar 16, 2016
    Posts:
    33
    I have a game with two controllable characters and am using Cinemachine with a Target Group to track them both, which works well.

    I now want to use a Cinemachine Trigger Action, with the Target Group itself as the trigger (i.e. any part of the total Target Group enters, it gets triggered, the whole Target Group has to leave to be un-triggered).

    I'm guessing this isn't supported, as I can't get it to work. I added a RigidBody and BoxCollider to my Target Group object, but nothing. Any ideas?

    (When selecting the Virtual Camera that uses the Target Group in the Scene View, it shows a bounding box around the Target Group, which is the bounding box I want to use as the trigger activator.)
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    This is not supported directly, but you could have a script on your Target Group. This script would create a BoxCollider and would dynamically set the bounds of the BoxCollider to match the bounds of the yellow box, which you see in the scene view.

    To get the bounds of the yellow box, do the following for example:
    Code (CSharp):
    1. public CinemachineTargetGroup targetGroup; // set in the editor
    2.  
    3. void Update()
    4. {
    5.         myBoxCollider.size = targetGroup.BoundingBox.size;
    6. }
    I created a small project and I could make it work this way. Hope it helps. :)
     
    falsevac and Gregoryl like this.
  3. falsevac

    falsevac

    Joined:
    Mar 16, 2016
    Posts:
    33
    Ah, that's great. Thank you!