Search Unity

Question Finding Free Look Camera position before it goes live

Discussion in 'Cinemachine' started by spiderinthesnow, May 1, 2022.

  1. spiderinthesnow

    spiderinthesnow

    Joined:
    Sep 30, 2021
    Posts:
    3
    I have a situation where I have two free look cameras that are positioned on objects in the scene, and the player can cycle between the two cameras to change which object they're viewing. For example:

    upload_2022-4-30_16-23-32.png

    The black circles represent the two free look camera orbits, the one around object 1 is the current camera view.

    I have a standard blend that I use between the cameras, and I've written some code to evaluate angles and distance between the two targets to try and prevent the camera from making an overly obtuse angle swing in the camera's rotation. The two free looks are set to world space binding and I'm using recentering with an x-axis adjustment to position the second free look camera to the place I want it to go before the transition happens, and so far that's been working pretty well for me.

    The problem I have is if the other free look camera is really far away or if there's an obstruction in the way - in cases like this, I'm opting to cut to the next camera. That said, the sudden cut transition feels kind of jarring to me, and I'd like to add a little bit of motion to make it look less abrupt. What I'd really want to do is set up a dummy virtual camera next to the new free look camera's position, cut to that, THEN use a blend transition to move it into place. Like so:

    upload_2022-4-30_16-42-10.png

    upload_2022-4-30_16-42-24.png

    The intermediate camera takes the same look at target as the free look camera that's being transitioned to but is set up with a cut transition, then the transition to the other free look is using a similar blend to the otherwise direct free look to free look transition I'd be using.

    My problem is that when I align the second free look camera in code, it doesn't seem to want to update the actual position until the camera goes live, which is an issue because I'd need to know where the camera is going to end up before that happens so that I can set up the intermediate camera at the right position to make the transition.

    Is there a way to force the free look camera to return the position it would be assigned before the transition happens? That, or is there another way to go about setting something like this up that doesn't involve as many steps?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    This is the part that I'm having some trouble grasping. I'm not sure of the algorithm you use to choose a position. And when you choose the position, does this involve computing X_Axis,Value and Y_Axis.Value and pushing that to the FreeLook?

    FreeLook does have this option built-in:

    upload_2022-5-4_16-59-37.png

    It will dynamically compute the appropriate X and Y axis values to put the camera as close as possible to the outgoing camera's position when it is activated.

    Another option is to use FreeLook.ForceCameraPosition to put the camera on the spot where you would put the intermediate camera, cut to it, and let the FreeLook's damping ease the camera into its final position. Of course that only works in you have enough position damping on the FreeLook.

    If you don't have damping and need to use the intermediate vcam, ForceCameraPosition should have immediate effect on the axes.
     
  3. spiderinthesnow

    spiderinthesnow

    Joined:
    Sep 30, 2021
    Posts:
    3
    Yeah, it's computing both of the axes and sending that to the FreeLook. The idea is that sometimes I want to adjust the Y rotation of the camera if it's close enough to a specific angle on the target, like if the current camera Y angle is 20 degrees away from facing the front of the new target it'll swing around a tiny bit to face the front as opposed to keeping the same rotation from before.

    I actually came up with an alternate solution that isn't exactly what I was aiming for but it's close enough - I set the intermediate camera up as a FreeLook, set the X axis of the intermediate FreeLook to a few degrees off the final Freelook position, cut to the intermediate then transition directly to the final FreeLook camera. I figured it cutting to another FreeLook with more or less the same parameters would set the position I wanted then allow the camera I'm actually switching to transition into place.

    I'm interested in the ForceCameraPosition method, I don't see it in the docs anywhere but I see it takes a position and a rotation, I'm assuming that's the exact position I'd want the camera to go to? If so, would I need to calculate that or would I just be able to use the camera's position/rotation after setting it?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    https://docs.unity3d.com/Packages/c...amera_ForceCameraPosition_Vector3_Quaternion_

    It will put the camera at the specified position and rotation, which you need to provide. However, if the camera has procedural motion enabled, it won't necessarily remain there. For example, in the case of the FreeLook, unless the camera is positioned exactly on the FreeLook's defined surface, the camera will move away from the specified position and settle onto the closest point on its defined surface. How quickly that happens will depend on the damping settings of the FreeLook. If damping is 0 then it will happen instantly.

    If you just want the camera to calculate its own position based on the nearest point on its surface to the outgoing camera, then InheritPosition will do that for you, and you don't need to calculate anything.
     
    Last edited: May 8, 2022