Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Transitioning follow target whilst maintaining relative position

Discussion in 'Cinemachine' started by ferretnt, Aug 1, 2019.

  1. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    I'm implementing Maya (or Unity Editor, if you prefer)-style controls. More accurately, we already have that without Cinemachine, but we'd like to replace the setup with Cinemachine, because Cinemachine's configurable orbit is great.

    Consider a scene with two objects (perhaps capsules) in it - A and B.

    We place a Freelook vCamera looking at each of A and B. Let's call them vCamA and vCamB.

    When initially entering the game, object A is the target, so we enable VCamA. That's fine. We rotate/tumble around object A. The user then highlights object B and presses "F" to frame it.

    At this point, we'd like to switch to using camera B. The tricky bit, is that when we switch to it, we'd like it to have the same rotation and position relative to ObjectB, asd vCamA had relative to ObjectA.

    We can't seem to find any way to do this. Things we have tried:

    - Tumbling both cameras simultaneously. This seems to require that they both be active.
    - Copying the transform from vCamA to vCamB when switching (vCamA is parented underObjA, and vCamB is parented under ObjB.)
    - Instantiating vCamB from vCamA, then changing its lookAt and follow targets.

    We *can* achieve the correct appearance by simply using a single camera and changing follow target, but then by design we get a cut not a transition, and nice-looking-data-driven transitions is pretty much what we want from Cinemachine.

    Nothing we have tried has worked, even for the most simple case with only two objects in the scene.

    Is there a way we can achieve this using Cinemachine, or is it just a bad idea?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Assuming that your FreeLooks' BindingMode is WorldSpace, then you can do this:
    vcamB.m_XAxis.Value = vcamA.mXAxis.Value;
    vcamB.m_YAxis.Value = vcamA.mYAxis.Value;
    vcamB.gameObject.SetActive(true);
    vcamA.SetActive(false);
     
    ferretnt likes this.
  3. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Thank you. With BindingMode as WorldSpace, the axis.Value, values now appear to be degrees for horizontal rotation and a number between 0 and 1 for vertical.

    I had actually tried assigning to axis.Vaue between the vCams yesterday, but was confused by the fact that with SimpleFollowWithWorldUp, the axis.Value seems to get consumed and reset to zero every frame, and I couldn't see anywhere where actual position information was cached. With WorldSpace it seems to work.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Yes, with SimpleFollow the X-axis binding mode is camera-space, so it must always be 0. If you want to use SimpleFollow as a binding mode, you'll have to do a little more work to get the effect you're looking for.
     
  5. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Nope, no need. Wordspace is working fine. Thanks for the help.
     
    Gregoryl likes this.