I’m having trouble understanding the pixel perfect camera in Unity. Although there are many threads about pixel-perfect implementation and jittering issues, none have fully clarified my questions.
My goal is to achieve pixel-perfect movement, where the actor moves smoothly within the pixel grid. I’ve set up a pixel-perfect camera based on this article, but during playtesting, I noticed that my camera or sprite suffers from jittering. I even tested the setup in a new Unity project using assets found online, but the jittering issue persisted.
Then you just need to update the above two points based on your GameObjects, no need to fiddle with rotations. As long as you move those positions smoothly, the camera will be nice and smooth as well, both positionally and rotationally.
I mean if you are getting a pretty good result without using pixel perfect camera, why bother(apart from automatically calculating the orthographic scale etc)?
Cinemachine was not pixel perfect and/or smooth in my case, so I made my own camera follow script for 2d
disable everything related to cinemachine in the test scene
make the camera’s parent null
add the PixelPerfectPlayerFollower script to the camera
if your player(the one that moves) isn’t the only gameobject that has the player tag, make the _player field of PixelPerfectPlayerFollower public or [SerializeField], and assign the player in the editor to PixelPerfectPlayerFollower component of the camera
change the other exposed fields of the camera such that it fits your project. For example if your project’s ppu is 128, set the ppu field of the PixelPerfectPlayerFollower to 128 etc.
Make sure your game view is in 1x and actual integer multiple of base resolution is selected
enter play mode, move the player(either with your code or dragging in scene); observe the camera smoothly following the player
You can follow a similar logic with the script above, you’ll store and manipulate the actual player position when you get input. Then, in late update you’ll snap the player to the closest pixel perfect position. Be careful to NOT calculating anything based on player’s pixel perfect position; only calculate stuff based on player’s actual position
I’m not trying to rotate the camera. All three rotation axes are maintained at “0” during play mode, so I don’t believe the issue lies with camera rotation. Here are some thoughts on the problem:
The Cinemachine camera moves to sub-pixel positions due to damping values.
The actor sprite does not completely snap to the grid because of acceleration and deceleration values.
Initially, I set the Cinemachine camera’s damping value to zero, thinking damping was the issue. However, I realized that the Cinemachine camera still jitters along with the actor. Here is a video demonstrating the issue. I’m not sure if my investigation is correct or if I’m entirely off track.
I also tried snapping the actor to the grid by rounding the actor’s position to the grid unit using the following code:
But this didn’t make any sense to me since pixel perfect camera already shifts the sprites to the pixel grid why would i try to shift the shifted position?