Search Unity

Parenting Object Under a Virtual Camera

Discussion in 'Cinemachine' started by thatscraigz, Jan 23, 2019.

  1. thatscraigz

    thatscraigz

    Joined:
    Mar 27, 2015
    Posts:
    100
    Hello!

    I often find myself wanting to parent objects under a VCAM set to POV to take advantage of the POV controls.

    My use case is things like cannons or something that you shoot from. Except it seems that objects nested under the VCAM don't inherit any sort of translation/rotation data like I would expect? Whenever I activate them my child geometry and spawn positions for projectiles just stay where they are (don't rotate).

    Is there something I'm doing wrong or a checkbox I'm missing somewhere?

    Thank you!

    craigz
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Not all camera movement is reflected in the vcam's transform. Use the Camera's transform as reference for spawning, not the vcam's transform.
     
  3. thatscraigz

    thatscraigz

    Joined:
    Mar 27, 2015
    Posts:
    100
    The issue is that different cameras (or cannons in my case) have different spawn points/nested models that need that info? So doing it in the hierarchy would be more convenient and less redundant?

    Is there any other way I could use the vcam's transform to GET the data so it can be a little more self contained within things like prefabs? Having to constantly source the cameras transform data (and needing to wait til transitions are over etc) seems like a large margin for error :/

    Totally could be a rookie mentality I'm having, but I just feel like it would make more sense?

    best,

    craigz
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You can't get it directly out of the vcam's transform, but you can get it out of the vcam itself.
    Code (CSharp):
    1. Vector3 pos = vcam.State.FinalPosition;
    2. Quaternion rot = vcam.State.FinalOrientation;
    will do the trick.
     
  5. thatscraigz

    thatscraigz

    Joined:
    Mar 27, 2015
    Posts:
    100
    Excellent! Thank you so much for the info, it means a lot to me :)
     
    Gregoryl likes this.