Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question How to get "base" position before camera shake

Discussion in 'Cinemachine' started by EmmetOT, Feb 3, 2022.

  1. EmmetOT


    Apr 25, 2016
    I'm applying a camera shake by setting the AmplitudeGain and FrequencyGain on the CinemachineBasicMultiChannelPerlin cinemachine component.

    I've encountered a situation in which I'd like to get the position of the camera, not including any camera shake. (I need an object to follow the camera but it can't be a child.)

    However I can't see where I would get the "base" camera position before the camera shake is applied every frame. I'm sure this is somewhere super obvious but I'm new to using Cinemachine.

  2. Gregoryl


    Unity Technologies

    Dec 22, 2016
    You can find it in CinemachineBrain.CurrentCameraState.RawPosition.

    Note that CinemachineBrain.CurrentCameraState is only valid very late in the frame, after CinemachineBrain has updated the camera position. This occurs in CinemachineBrain.LateUpdate, which has an extra late execution order. Your follow script needs to run after that. You can hook into CinemachineCore.CameraUpdatedEvent to be sure to run your code at the right time.
    matt1101, EmmetOT and antoinecharton like this.