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

    EmmetOT

    Joined:
    Apr 25, 2016
    Posts:
    44
    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.

    Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,331
    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.