Search Unity

Pixel Perfect Camera - Darn Dancing Walls! (Solved)

Discussion in '2D' started by Cody-Rauh, Apr 20, 2020.

  1. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    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.
     
    Last edited: May 1, 2020
  2. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    Bumping for help.
     
  3. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    Not making progress, would still be grateful for help.
     
  4. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    Still haven't found a solution.
     
  5. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    Any love out there for the struggle?
     
  6. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    Updated, this is a very challenging issue.
     
  7. DragonKinzly

    DragonKinzly

    Joined:
    Jan 13, 2020
    Posts:
    1
    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. :)
     
  8. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    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
     
  9. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    @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.
     
  10. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    @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?
     
  11. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
  12. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    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.

     
  13. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    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?
     
  14. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    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!
     
  15. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Any means will do! Dropbox, Google Drive, etc.
     
  16. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    I sent the package to you in your PM's thank you very much for responding, I hope this can be fixed!
     
  17. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    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.
    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:
    1. Right click on the 2D Pixel Perfect Camera folder in the Project view, and 'Show in Explorer' or 'Reveal in Finder'.
    2. Move this folder from the Library/Package Cache to your Packages folder.
    3. Locate and open PixelPerfectCamera.cs.
    4. Comment out the two lines of code at line 218 and line 223.
      Code (CSharp):
      1. //PixelPerfectRendering.pixelSnapSpacing = m_Internal.unitsPerPixel;
      2.  
      3. //PixelPerfectRendering.pixelSnapSpacing = 0.0f;
    5. 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.
     
    Last edited: Apr 30, 2020
  18. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    @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.



    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.



    Also thank you for taking time out of your day to help with this, very much appreciated!
     
    Last edited: Apr 30, 2020
  19. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    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.
     
  20. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    @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!
     
  21. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    @yuanxing_cai I overhauled all the assets in the scene to have matching PPU with the camera, everything is 1:1 scale, all things set as per the document. The sprites themselves all look wonderful as you can tell from the GIF.

    However zero improvements for the wall, I rebuilt the tileset and followed the directions, I even made the tile itself the same dimension as the PPU, and it is still having a wiggle. However, if you look really closely it only happens on the side exposed to the border of the tiles in the scene, where the Walls meet the Floor.

    If all the PPU is matched up entirely, and there is zero issues for the sprites and the tile palette images are set up with the same settings as the sprites, why is the problem exclusive to only the edge of the tileset?

    If I had the settings wrong in the project at this point wouldn't I still have the same problem on my sprites as well?
     
    Last edited: May 1, 2020
  22. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256


    So close, just wish I knew why the wall's behavior (Tile Palette) is different than Sprites with the same settings. o_O

    @yuanxing_cai figured this might help as it shows the contrast... between sprite and wall behavior. I figure after adjusting all the settings to the same, shouldn't the sprites be behaving the same as the wall if it is just the difference of falling between pixel alignment of 0 - 1?
     
    Last edited: May 1, 2020
  23. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    I found the solution... will write up a tutorial to help the next poor bastard out who runs across this issue. :)
     
    TheHolyAvatar likes this.
  24. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Nice! What did you do? I couldn't reproduce the 'dancing pixels' issue on the walls once I enabled Pixel Perfect Camera in the project you sent me.
     
  25. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    So the issue for me is primarily that the stand-alone sprites have an alpha on all sides, where the tile sprites went all the way to the edge/border of the image. So the Alpha helped created a feathering effect vs. the Tile Sprites ended abruptly at the edge of the image, no feathering.

    I have seen this before in Unity with an edge bleed on Sprites, where the bottom ends up at the top, it is a similar but not the same mechanic. This also happens on 3D models as I am sure you know.

    So for any tile edges that won't be side by side to another tile, I created a 3-pixel alpha edge.

    Another issue is I think I was trying to squeeze too many pixels into the screen area, as changing camera size from 15 to 10 also helped all sprites just a little more. I do plan to write up a full tutorial on this with images, explanation etc.
     
  26. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    @yuanxing_cai as promised the tutorial write up!

    https://codyrauh.com/trouble-shooting-001-2d-games-non-retro-bit-style

    Also, I am still having a couple of problems with frame rate hitching, not sure what is causing it on my computer, however, it only happens on Unity Engine built games. If you have the time Yuanxing would appreciate you taking a look if this is part of your skillset, or if you know the correct Unity team member who could assist with this!

    https://forum.unity.com/threads/iss...ty-build-editor-unity-games-by-others.883747/
     
    Last edited: May 6, 2020
    yuanxing_cai likes this.
  27. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I'm glad you finally resolved all of your issues!
     
  28. Cody-Rauh

    Cody-Rauh

    Joined:
    Oct 12, 2013
    Posts:
    256
    Thank you and super appreciate your help. It was a multilayer problem which made it tricky.