Question by
Dylanrey · Jan 07, 2019 at 08:24 PM ·
camera-movementbackgroundpixelcamera followparallax
Pixel Perfect Camera jittering in Parallax Background
Hi guys, I got a problem using the PixelPerfectCamera while using the background Parallax.
The background parallax are some Quads moving the offset.
sample code for Parallax -->
void FixedUpdate() {
parallax_X = (previousCamPos.x - cam.position.x);
parallax_y = (previousCamPos.y - cam.position.y);
offset.x = (parallax_X * - speedX);
offset.y = (parallax_y * - speedY);
//material.mainTextureOffset = offset;
material.mainTextureOffset = PixelPerfectClamp(offset);
}
private Vector2 PixelPerfectClamp(Vector2 moveVector) {
float pixelsPerUnit = 32f;
Vector2 vectorInPixels = new Vector2 (
Mathf.RoundToInt (moveVector.x * pixelsPerUnit) / transform.localScale.x,
Mathf.RoundToInt (moveVector.y * pixelsPerUnit) / transform.localScale.y);
return vectorInPixels / pixelsPerUnit;
}
While the camera follow the Player like this -->
void FixedUpdate () {
float posX = Mathf.SmoothDamp(transform.position.x, target.position.x, ref velocity.x, smoothTimeX);
float posY = Mathf.SmoothDamp(transform.position.y, target.position.y, ref velocity.y, smoothTimeY);
Vector3 move = new Vector3 (posX, posY, transform.position.z);
transform.position = PixelPerfectClamp (move);
}
private Vector3 PixelPerfectClamp(Vector3 moveVector) {
Vector3 vectorInPixels = new Vector3 (
Mathf.RoundToInt(moveVector.x * 32f),
Mathf.RoundToInt(moveVector.y * 32f),
-10f);
return vectorInPixels / 32f;
}
Without the PixelPerfectClamp all become super jittered! so at least this trick helped, but I still get the jittering... anyone has solved it? Thanks in advance!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612185317im_/https://answers.unity.com/themes/thub/images/avi.jpg)