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.
  2. Dismiss Notice

Question Position Correction confusion

Discussion in 'Cinemachine' started by xorblax, Apr 6, 2023.

  1. xorblax

    xorblax

    Joined:
    Jul 15, 2018
    Posts:
    25
    I don't understand the use of position correction. My understanding from the manual is that you can use it to add adjustments to the final position/rotation of the camera without that adjustment being fed back in for the next frame. However, despite the value of state.PositionCorrection going to zero at each frame, the value of state.CorrectedPosition does not, adding into itself until my memory overflows. What is incredible is that it even retains its value upon exiting play mode, and keeps it until I recompile the scripts. Seems to me like something going very wrong.
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    That does not sound right.

    What version of Cinemachine are you using?
    How are you setting state.PositionCorrection? Can you provide some code or a project?

    Code (CSharp):
    1. CorrectedPosition = RawPosition + PositionCorrection;
    So CorrectedPosition could only blow up if RawPosition is set to CorrectedPosition somewhere or if PositionCorrection is cumulative (which it should not be, because it is reset to 0).
     
  3. xorblax

    xorblax

    Joined:
    Jul 15, 2018
    Posts:
    25
    I'm using version 2.8.9, and this is the code I used to test this, placed in a post pipeline callback extension.
    Code (CSharp):
    1. if(stage == m_ResultStage){
    2.      Debug.Log(state.PositionCorrection);
    3.      Debug.Log(state.CorrectedPosition);
    4.      state.PositionCorrection = Vector3.forward * 400;
    5. }
    Looking at it now, I do access the actual mainCamera object in order to call WorldToViewportPoint, because I couldn't find an equivalent thing for a virtual camera... I think this is the problem, as when I remove my methods that call stuff from mainCamera, the PositionCorrection accumulating doesn't happen anymore.
     
  4. xorblax

    xorblax

    Joined:
    Jul 15, 2018
    Posts:
    25
    Something that helps is making sure to set the mainCamera transform equal to state.RawPosition at the start of the extension. I think the way it works is at the start of each frame, the virtual camera rawposition and the actual camera position are not the same, because the camera keeps the positioncorrection adjustment from before; this being what causes the issue with my calls to stuff like mainCamera.WorldToViewportPoint.