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

Set FreeLook camera position at runtime.

Discussion in 'Cinemachine' started by Michal_Stangel, Sep 23, 2020.

  1. Michal_Stangel

    Michal_Stangel

    Joined:
    Apr 17, 2017
    Posts:
    151
    Hello,
    Is it possible to place FreeLook camera to given Vector3 at runtime? I sometimes need to show camera's target from specific distance and angle, but let player to control the camera (zoom and rotation).

    I know that it should be possible to use Inherit Position to keep camera transform position when script is initialized, but is it possible to override camera transform if camera is live?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    CM 2.6.3 has a new API: FreeLook.ForceCameraPosition that should do the job.

    Code (CSharp):
    1.         /// <summary>
    2.         /// Force the virtual camera to assume a given position and orientation.
    3.         /// Procedural placement then takes over
    4.         /// </summary>
    5.         /// <param name="pos">Worldspace pposition to take</param>
    6.         /// <param name="rot">Worldspace orientation to take</param>
    7.         public override void ForceCameraPosition(Vector3 pos, Quaternion rot)
    8.  
     
    Seith likes this.
  3. Michal_Stangel

    Michal_Stangel

    Joined:
    Apr 17, 2017
    Posts:
    151
    Wow, that method even has the same name as one I prepared to manage it :)
    Works great. Thanks, Gregory.
     
    marc_tanenbaum and Gregoryl like this.
  4. brokenspiralstudios

    brokenspiralstudios

    Joined:
    Oct 20, 2021
    Posts:
    40
    @Gregoryl How would you do the same for a Cinemachine Virtual Cam? Using ForceCameraPosition does nothing. Thanks!
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    It should work the same way for non-FreeLook vcams.