- Home /
Parallax displacement after changing "frame/view"
Hi!
I'm using the script I found here:
https://answers.unity.com/questions/551808/parallax-scrolling-using-orthographic-camera.html
It works great when using in one "frame/view", but when I use it together with cinemachine and swap frame (move forward in my game), the layers that uses parallax have been moving while I'm in the first scene (despite disabling the gameobjects of all frames I'm currently not in). I tried to reset position and stuff but can't get it to work.
The problem goes away if I put 1 main camera in each frame as I saw on a youtube tutorial, and there's no displacement, but it makes my dash function that uses the mouse position for direciton want to dash towards the main camera of the first scene, which isn't something I want..
Some ideas I've got to fix it but can't implement: - Only let the active layer use parallax - Reset backgrounds to original position when entering Trigger Action (tried this with FindObjectTag to no avail) - Put backgrounds at an offset to the distance I've moved in 1 screen (prefer not to use this)
I use Cinemachine confiner and trigger action script to change the view, and the displacement is exactly the amount the camera changes from screen to screen, in x position. Hope I'm making sense... Would appreciate any help!
Thanks!
Answer by cephantielle · Nov 15, 2020 at 02:20 PM
I found a solution!
Might not be the prettiest but at this point I don't really care! Despite the gameobject parent being disabled, the scripts in the children were still running (hence the displacement).
My solution was to disable the ParallaxBackground on my mainFrame object, and add a OnTrigger2DCollision box (as a child) a bit further into the new scene (if you place it immediately or using the Cinemachine Confiner, the offset still appears) and all the script does it to activate the parent ParallaxBackground script. Hope someone can get some use out of this in the future as it's literally not mentioned anywhere and other solutions seem to come with other problems (such as my direction-dash). Works flawlessly!.