# how to fix jitter on a parallax?

I’m pretty new to Unity. I recently used the tutorial by code monkey found here on how to make a parallax background. It kind of works, but for some reason it is jittering. it didn’t seem to jitter in the video so I’m a little bit confused. is there any way I could add a smoothing effect to the code?

``````    [SerializeField] private Vector2 parallaxEffectMultiplier;

private Transform cameraTransform;
private Vector3 lastCameraPosition;

private void Start()
{
cameraTransform = Camera.main.transform;
lastCameraPosition = cameraTransform.position;
}

private void Update()
{
Vector3 deltaMovement = cameraTransform.position - lastCameraPosition;
transform.position += new Vector3(deltaMovement.x * parallaxEffectMultiplier.x, deltaMovement.y * parallaxEffectMultiplier.y);
lastCameraPosition = cameraTransform.position;
}

}
``````

Use FixedUpdate instead of Update. Worked for me!

Here is my “Parralax 2d Code” I use, it has “smoothing”:

``````    Transform cam; // Camera reference (of its transform)
Vector3 previousCamPos;

public float distanceX; // Distance of the item (z-index based)
public float distanceY;

public float smoothingX = 1f; // Smoothing factor of parrallax effect
public float smoothingY = 1f;

void Awake()
{
cam = Camera.main.transform;
}

void Update()
{

if (distanceX != 0f)
{
float parallaxX = (previousCamPos.x - cam.position.x) * distanceX;
Vector3 backgroundTargetPosX = new Vector3(transform.position.x + parallaxX, transform.position.y, transform.position.z);
transform.position = Vector3.Lerp(transform.position, backgroundTargetPosX, smoothingX * Time.deltaTime);
}

if (distanceY != 0f)
{
float parallaxY = (previousCamPos.y - cam.position.y) * distanceY;
Vector3 backgroundTargetPosY = new Vector3(transform.position.x, transform.position.y + parallaxY, transform.position.z);
transform.position = Vector3.Lerp(transform.position, backgroundTargetPosY, smoothingY * Time.deltaTime);
}
previousCamPos = cam.position;
}
``````