I’m trying to create a 2D sidescroller that implements a parallax effect for the background (there is also a ground which does not use the effect). The camera follows the player, and the player controls a unit that can move left and right. In other words, there is no set speed for the ground to move at so I can’t just have the background scroll at a fraction of the speed as the ground.
My current solution is to move the background a fraction of the player’s x velocity. I add this in the update function of the backgrounds script:
transform.position = transform.position + Vector3.right * playerRb.velocity.x * Time.deltaTime * 0.9f;
Here, i’m trying to make the background scroll at 90% of the player’s speed. This actually seems to work, except for the fact that it is extremely jittery when I test it in Unity (I left out infinite scrolling for now).
Does anyone know why this may happen? Is there something wrong with the way that I position the background images?