- Home /
Camera movement in a pixel perfect 2D game, how to do it the right way?
I have been trying to figure out pixel perfect movement in Unity for a while no with little to no success. Well, after fiddling around for several nights, my game is pixel perfect and movements are smooth BUT once the camera moves, all hell breaks loose.
My tile size is 16x16 that is my PPU on every sprite, the pixel perfect camera etc.
What I did so far:
set all sprites to what official Unity Blogposts suggest: 16 ppu, no compression, point filter
installed the pixel perfect camera picture, tried several retro resolutions 256×224 , 256x144 , and even 720x480
enabled pixel snap on the material (honestly, with the pixel camera this hardly does anything)
I read into how they moved the sprites in super mario land on the snes, the basically divide each pixel into subpixels and move their character in a virtual position and align it to the closest pixel on the grid, that what I do, and characters now move pixel perfect across the screen (this and the pixel perfect camera component have given the best results by far)
disabled anti aliasing
turned off vysnc and locked the fps to 60
With all this in place, the game looks crisp, movement is smooth and pixel perfect BUT once I move the camera, there is distortion, stutter and artifacts. It is especially bad when moving diagonally. I tried locking the camera position to the closest pixel but this doesn't help. I just don't know what to try anymore. I know it can be done, I just don't know how.
All the code can be found here: https://github.com/SpaceKuh/reallypixelperfect It's messy and all over the place because at this point I have just been experimenting, trying to see what works and what doesn't. I'd be so happy if anybody could help!
I've read you code on camera movement. Its doing in update but from my experience, fixedupdates prevents stutter, lag and etc unwanted distortions.
Have you tried to use fixed update yet?
I'll look into it when I get home from work! I've tried fixed update before and it didn't really change anything, but maybe I've missed something