Pixel Perfect Camera - Darn Dancing Walls! (Solved)

Hello!

UPDATE: PLEASE go all the way to the bottom of the thread(page) for the current issue!

I am working with a 2D scene, in which I am struggling with choppy movement caused by the Unity - Pixel Perfect Camera Component. I have to resolve this issue before I can move forward in case of major rework of the assets of some sort.

Please see link for GIF's and further detail: https://imgur.com/a/H63WkYv <--- GIF's Here!!!

I am trying to get the completely smooth movement I get with player and camera when PPC is off, but also get the benefits of when PPC is on by not having sprites and tiles in the scene have distortion waves.

Help would be greatly appreciated.

  • Cody

UPDATE: As confirmed by several, the issue lies in the fact that the game uses 2D physics for all moving objects. These moving objects don't move entire whole pixels at a time. Thus, will land at .3 or .05 or .99 of a pixel. I don't know how to Mathf clamp the rendered pixels of these objects without impacting the velocity of the rigid bodies physics!

Please help!

Disclaimer: 2D physics is essential for this project as the majority of interactive objects are heavily dependent on physics for proper interaction in some way.

Bumping for help.

Not making progress, would still be grateful for help.

Still haven't found a solution.

Any love out there for the struggle?

Updated, this is a very challenging issue.

Have you tried turning OFF - Pixel Snapping in Pixel Perfect Camera?

Otherwise it sounds like you would want to clamp your acceleration to whole numbers or increase the number of pixels on the screen.

On a side note, I would make your box a child of the player object, instead of using a follow script. You can then SetActive() whenever you want it visible and you aren't doing tough (force) processing twice; as it uses an offset from your player instead.

Those are my 2 cents, I am fairly new to unity and have never worked with pixel perfect camera.
-Retro games are cool as &^%$ though. Keep fighting the good fight. :)

ISSUE STILL UNRESOLVED - Thank you for the reply though witrob02!

Pixel Snapping has been off by default, but a good question! Tried both on and off, no change in results.

Screen resolution in the current build is 1024x768 with a 75 PPU for correct scene scaling. Increasing PPU has not improved the issue.

The clamping 2D physics is the part I am struggling to figure out ( I don't know how ), as Unity's physics engine isn't designed for absolute control down to the pixel and I worry about clamping math creating some strange physics outcomes.

The emote box is a child of the player, no follow script used, only the camera has the following script. the problem is the Pixel Perfect Camera Unity is rounding them non-uniform as the box could be rounding up while the player rounding down depending on how close each is to the nearest whole pixel.

This issue isn't just affecting the emote box it is effecting the entire scene.

No worries and good suggestions, and thank you, here is the discord if you are interested in keeping up to date on progress: https://discord.gg/vMDzwNc

@rustum @yuanxing_cai is 2D physics not compatible with the pixel-perfect camera component? I have been on Discord servers, Facebook Groups, and this forum searching for help, I even made a post on Twitter, no one seems to know how to fix this, that or they aren't willing to share.

This problem affects every asset in the scene and literally causes eye strain for the player.

@thomak-dev was your issue regarding your Text Jitter similar to the jitter I am showing in my GIF's? Did you find a fix?

@BusyRoots_1 I looked through your tutorial, I read through your thread, I was wondering if you fixed this problem for 2D physics yet? https://discussions.unity.com/t/695194/5

It seems you got it hammered out for 2D games without 2D physics but couldn't see where you had solved it for games with 2D physics enabled.

Starting to think this is not possible...

If you look at their video you see the same movement issues towards the end.
This is so disheartening, cause I am not even trying to make a pixel game, just trying to have clean images during motion without the wave/distortion that you see in GIF #4, something pixel perfect was designed to resolve.

Unfortunately, though the movement is not nearly as smooth as Unity seems to claim.

https://www.youtube.com/watch?v=CU4YjSZNTnY|start=140

Hey Cody! Is it possible that you send over a test project so that we can take a closer look at what might have caused the issues?

Yeah, I can do that if you tell me where to send, will have to duplicate and strip out down to a bare minimum. Your looking at it is GREATLY appreciated!


Any means will do! Dropbox, Google Drive, etc.

I sent the package to you in your PM's thank you very much for responding, I hope this can be fixed!

Hi @Cody-Rauh

To achieve 100% pixel perfectness, internally Pixel Perfect Camera has to snap the positions of both the sprites and the camera to a pixel grid before rendering. This always happens regardless of whether the Pixel Snapping option is on.

Unfortunately, the snapping of sprite positions doesn't play too well with physics driven movements, or rather, any type of movements that displace the sprites by an arbitrary distance. A common symptom of this is when two physics driven objects are moving at the same velocity (think a character pushing a box), they may jitter in relation to each other.

That being said, it appears to me that you are not going after a pixel-art style for your project. Your sprites are bi-linear filtered instead of point-filtered. In this case, you might want to disable the sprite position snapping (but keep the camera position snapping) as a compromise. As a result, you'll get uneven borders on your icons (see the screenshot below), but they will not 'swim' or 'wave' as the the camera pans.
5784370--610441--upload_2020-4-30_12-16-7.png

There's currently no way to disable sprite position snapping via the UI, you'll have to modify the code:

  • Right click on the 2D Pixel Perfect Camera folder in the Project view, and 'Show in Explorer' or 'Reveal in Finder'.
  • Move this folder from the Library/Package Cache to your Packages folder.
  • Locate and open PixelPerfectCamera.cs.
  • Comment out the two lines of code at line 218 and line 223.
//PixelPerfectRendering.pixelSnapSpacing = m_Internal.unitsPerPixel;

//PixelPerfectRendering.pixelSnapSpacing = 0.0f;
  • Go back to Unity and wait until it finishes compiling the modified code.

Play your level and movements jitter should be gone. There should also be no swimming pixels around your walls either.

If the uneven lines bother you too much, try generating mipmaps for your sprites and maybe enable trilinear filtering. Doing these will help eliminating the the uneven lines but they also tend to make your sprites blurry.

Hope you find the information useful.

@yuanxing_cai first of all, thank you very much, I do believe it is an improvement in both clarity and smoothness, much deeper in problem-solving then my skill could have taken me, and I didn't even know that Unity's deeper systems were in fact just more C# that could be modified, so I also learned something valuable. ( and probably dangerous, ha! )

That said one last issue is still obvious and bothersome, and testing by users has listed this as a large complaint, which is the wall still appears to be moving to the eye vs. feeling solid in place. Nearly everything else in scene right on point, camera movement and player movement all feel pretty good, yet that darned wall is still jiggling like a fat man.

How can I get the wall (Grid Palette/Tiles ) to behave more like the sprites in the scene? It just seems to move and wiggle so much more than even the sprites, which I find odd for something accurately placed.

Also don't mind the movement of the player I am simply just bumping him along slowly to make the wall problem easier to see in comparison with the other sprites.

falsenegligibleblobfish

P.S. Just wanted to send a second GIF to show you how smoothly boxes are behaving now compared to the walls, things are much much smoother, which makes me confused why the walls are behaving how they are when the boxes and everything else appears so much more accurate with much thinner lines and details that could fall between pixels on the screen.

Additional P.S. I have since also converted the project to URP since sending you the project if this information is helpful.

victoriousnastyambushbug

Also thank you for taking time out of your day to help with this, very much appreciated!

It's probably the PPU and Reference Resolution settings. The project you gave me isn't properly set up for those.

The Assets Pixels Per Unit should match the value that your sprites use (100 if I remember correctly). This is very important in eliminating the swimming pixels.

And the Reference Resolution should be a rather small value, like 320 * 240.

I can't explain everything in detail here. That's what the documentation is for :) https://docs.unity3d.com/Packages/com.unity.2d.pixel-perfect@3.0/manual/index.html

BTW you don't need URP if you don't use 2D lighting.

@yuanxing_cai Understood, I will go back and implement changes after some sleep, let you know the outcome.

The URP conversion is due to later plans to implement lighting in specific portions of the game, as well as the need for some shader graph functionality. Thank you and I hope your day goes well, and your family is all safe and healthy!