It is called in Update. I tried changing it to LateUpdate, but had the same results.
If I turn Cinemachine off and have the camera just follow the player, it works perfectly. But with Cinemachine on, the background jitters back and forth.
If I use the transform of the Cinemachine instead of the Camera, I still get jitters, in addition to some weird behaviour, especially when reaching the edges of Cinemachine Confiner.
Any suggestions?
Edit: apparently, if I use the transform of the Cinemachine to calculate horizontalCameraMovementInLastFrame, the jitters only occur when playing the Scene with Maximize On Play in the editor. If I play it in the editor without Maximize Window, or if I build an executable, it doesn’t jitter at all. However, it still acts very weird when reaching the edges of Cinemachine Confiner.
In CinemachineBrain the Update Method was set to Smart Update, and Blend Update Method was set to Late Update. I tried changing Update Method to Late Update, but there’s no difference. Code is currently running in LateUpdate.
Move code in Update, Brain in LateUpdate so the camera only moves after your transforms are complete.
As far as the jitter at the bounds, I never figured out how to fix that. Ended up reducing the zoom so the object could never get so close to the edges, maybe someone else has something better as far as that goes.
edit just to be clear, anything that changes your camera positions should be in LateUpdate, anything that moves your objects should be in Update.
I moved code back to Update, set brain to LateUpdate (Not sure what SmartUpdate is), problem persists.
Then thing is that when I use position of Transform of CinemachineVirtualCamera as reference, I don’t get any jitters at all (except in Maximize On Play in the editor). When I get close to the bounds of Cinemachine Confiner, I don’t get jitters. Rather the background keeps scrolling (because the CinemachineVirtualCamera is still moving), despite the actual camera standing still, which looks very weird.
The only solution I can think of right now is to use Transform of CinemachineVirtualCamera as reference, but disable the parallax script when Cinemachine Confiner kicks in. No idea how to determine when that happens though…
Also, regardless if I use Camera Transform or CinemachineVirtualCamera Transform as reference, there are no jitters in Scene window, only in Game window.
Edit: ok, this is weird, but putting the code in FixedUpdate solved it… Not sure this is a good solution, but it does work…
Another solution is to change the priority of the scripts. Cinemachine will try to execute after your parallax changes have been made. But you want your parallax changes to take the Cinamachine into account.