Search Unity

Question Clear Shot camera children that are not actual children of the gameobject

Discussion in 'Cinemachine' started by sebastianzander, Jul 22, 2021.

  1. sebastianzander

    sebastianzander

    Joined:
    Mar 22, 2018
    Posts:
    37
    My game world consists of several 3D terrain tiles that together with a floating origin are able to move and do not have fixed world space positions. Now I wanted to add some kind of "landmark" cameras to each terrain tile. Of course, their transforms have to translate with their terrain tile.

    CinemachineClearShot unfortunately only seems to support direct children of its game object. As I can't make CinemachineClearShot the children of multiple terrain tiles, I am not sure how to proceed. I have a custom CameraSwitcher component which switches between vehicle and gameplay context specific cameras. Via input the user shall be able to override these cameras with the Clear Shot, which in turn should be able to choose the ideal landmark camera.

    Is there a way to avoid adding multiple CinemachineClearShot cameras, one for every terrain tile?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You can dynamically reparent tile vcams to/from your clearshot
     
  3. sebastianzander

    sebastianzander

    Joined:
    Mar 22, 2018
    Posts:
    37
    Thank you for your reply. It works for now. I have my clear shot vcams persistently stored under the terrain tile together with a MonoBehavior which holds a list of them. When the game starts I reparent them under my CinemachineClearShot game object. But instead of reparenting them back under their terrain tile when the world translates, I simply translate them the exact same amount as I translate their superordinate terrain tile. I tried parenting them under their terrain tile just for the short period in which the terrain tile gets translated, but it seemed that I would have to pass at least one frame before translation propagated through the hierarchy. At least this is what I think happened, because the vcams did not translate with their tile.

    It also looked as if calls to CinemachineVirtualCameraBase.OnTargetObjectWarped did interfere with the translation. Does OnTargetObjectWarped also translate its attached transform or does it only update the internal state?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    I don't see why this should be, unless your translation happened very late in the frame. If it happens during Update(), the effect should be immediate.

    It only affects the internal state relating to the warped target. The transform is untouched.

    If you'd like to prepare a simple test project that shows the issues you are having, I can take a look at it.
     
  5. sebastianzander

    sebastianzander

    Joined:
    Mar 22, 2018
    Posts:
    37
    There may had been a bug, I don't know. Fortunately, it is gone now and I can't reproduce it.

    I fixed the issue regarding OnTargetObjectWarped. Previously, I called this on all CinemachineVirtualCameraBase that I could find in the entire scene. Now I don't call it on cameras that are/become children of CinemachineClearShot since they have a fixed position and don't have Follow set, don't orbit or do anything else. They just look towards LookAt. For them it is enough to translate them in parallel with the rest of the world.

    I actually only call OnTargetObjectWarped on CinemachineFreeLook cameras that orbit vehicles. I guess OnTargetObjectWarped is only required when anything is damped or smoothed.