I have a background element (a distant island) that I am applying this script to. It is supposed to have a very small parallax effect, so I used a value of .98
, where 1
= no parallax effect. However, while the parallax effect essentially works, it jitters a pixel or two quickly left/right and up/down at random intervals.
The Cinemachine camera is set to follow the player.
public class Parallax : MonoBehaviour
{
private float startpos;
private float startposy;
public GameObject cam;
public float parallaxEffectX;
public float parallaxEffectY;
void Start()
{
startpos = transform.position.x;
startposy = transform.position.y;
}
void Update()
{
float dist = (Camera.main.transform.position.x * parallaxEffectX);
float disty = (Camera.main.transform.position.y * parallaxEffectY);
transform.position = new Vector3(startpos + dist, startposy + disty, transform.position.z);
}
}