pixel perfect camera in unity without the jitter (what finally worked for me)
Contents
been fighting jittery pixel art in my farming game for literally weeks so heres everything that ended up mattering. this is URP 2D on unity 2022 LTS but most of it applies to newer versions too
1. one pixels per unit for everything
pick a PPU (i use 16 because my tiles are 16x16) and set EVERY sprite to it. one sprite at a different PPU and it gets scaled weird and shimmers when it moves. i had the player at 16 and the trees at 100 (the default) for months and couldnt work out why the trees looked mushy lol
2. import settings
- Filter Mode: Point (no filter)
- Compression: None
- mip maps off
make a preset with these and set it as the default for your art folder so you dont forget on new sprites
3. the pixel perfect camera component
add Pixel Perfect Camera to your main camera, set Assets Pixels Per Unit to your PPU and the reference resolution to your target. mine is 320x180, which scales cleanly to 1080p, 1440p and 4k. tick Upscale Render Texture if you want everything snapped to the grid, rotated stuff included, or leave it off if you need smooth UI on top
4. cinemachine is the jitter
if youre using cinemachine, add the CinemachinePixelPerfect extension to the virtual camera. without it cinemachine moves the camera to sub-pixel positions, the pixel perfect camera fights it, and you get that awful shaking every time the camera follows the player
5. player movement
my player had a Rigidbody2D and i was moving it in Update. physics runs in FixedUpdate so the sprite only moved on physics steps and looked stuttery on high refresh screens. two fixes: move rigidbodies in FixedUpdate, and set Interpolate on the player's Rigidbody2D so rendering smooths between physics steps
6. dont fight non integer scaling
if the window is a weird size, pixel perfect camera will letterbox or crop. thats fine. way better than stretching 320x180 to 1366x768 and getting uneven pixels. my game gets black bars on some laptops and nobody has complained once
after all this the game finally looks crispy. now i just have to finish the other 90% of it. heaps of thanks to the random forum posts from 2019 that got me here
Written by
Jake Morrison
indie game dev in melbourne, making a cosy farming game in unity that is definitely shipping this year (3rd year saying this). shaders, pixel art, coffee
Get the best of #unity weekly
One email each Monday with the most useful posts. No spam; unsubscribe in one click.
Comments
Sign in to join the conversation.
Sign in to comment