Unity pixel perfect camera and jittering

So I had issue with my player jittering while moving but I managed to fix it by this

newPosition.x = Mathf.Round(newPosition.x * 32f) / 32f;
 newPosition.y = Mathf.Round(newPosition.y * 32f) / 32f;

But I also have my custom cursor and fog of war attached to my player as child and they just keep jittering when moving with the player and I cant find a fix

   public GameObject player;
    public float rotationSpeed = 5f;

    void LateUpdate()
    {
        Vector3 mousePosition = Input.mousePosition;
        mousePosition.z = Camera.main.nearClipPlane;
        Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
        transform.position = worldMousePosition;

        Vector3 directionToPlayer = player.transform.position - transform.position;

        float angle = Mathf.Atan2(directionToPlayer.y, directionToPlayer.x) * Mathf.Rad2Deg;
        angle += 90;
        Quaternion targetRotation = Quaternion.Euler(0f, 0f, angle);
        transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
        Cursor.visible = false;
    }

Here is the code

I found the issue when I have my player in hierarchy selected so I can see it´s transfrom the jittering is happening when I select something else it stops???

Jittering occurs all too easily when you have pixel snapping or worse “upscale render texture” with a very low resolution enabled, and at the same time set your pixels per unit ratio to a low value.

Try increasing pixels per unit as I’ve done here:

This smoothes out the pixel perfect placement. Because if you go the opposite direction you’ll notice that pixel snapping respectively the low resolution naturally leads to jittering. The important clue here is the pixel ratio, if it’s pretty high like 20:1 jitter will be heavy while at 4:1 or 2:1 it’ll be barely noticeable.

Try 5 pixels per unit for instance and you’ll see objects making big jumps while they are moving because the virtual pixels are HUGE in this case. Or in other words objects move in 0.2 unit steps and nothing in-between in order to remain pixel-perfect aligned.

My assets are 32x32 sprites and when I use 32 ppu I get complete jitter unless Grid Snapping is off. Even with the default 100 they jitter. So I opted for 320 to give them ample virtual pixels to move between but in all honesty, this defies the purpose of pixel snapping so it could as well be turned off.

The RenderTexture option to me is not very well explained and I wonder what the use of this is. It always leads to degraded quality. May require assets specifically made for this.

Pixel snapping:


Upscale RenderTexture:

Here’s the difference between 320 ppu vs 8 ppu:

1 Like

jeez, that IS annoying, like really, I HAD to deal with it before…