Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Smooth camera follow without pixels deforming

Discussion in '2D' started by GreenPhotonRays, Jul 3, 2023.

  1. GreenPhotonRays

    GreenPhotonRays

    Joined:
    Feb 25, 2022
    Posts:
    11
    Hi,
    I have this little game Im working on. It is a top down rpg of some kind and I tried implementing real pixel art, but I came to this graphical issue:
    when I moved my character my camera followed smoothly and that caused the pixels from obstacles, tiles, etc. to deform.
    I researched a bit, and found out, that the camera needs to be on full int coordinates and you can use a component called "pixel perfect camera".
    This worked... but the camera was now "stuttering". With that I mean the coordinate jumps of the full int moving camera were so big, that you noticed the snapping when the camera moved slowly, because then normally it interpolates between two int values. I hope you know what I mean.
    There are many games like hyper light drifter, etc. that have smooth camera movement and still havent got this pixel deformation issue.

    Do you know any solution or is it simply not possible in unity?

    Thanks in advance!
     
  2. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    theres not 1 simple fix

    you will have to research pixel perfect, and take all the steps, unless you do them all perfectly it wont look like you want it
     
  3. GreenPhotonRays

    GreenPhotonRays

    Joined:
    Feb 25, 2022
    Posts:
    11
    yeah I tried to do such things too, but even if I replicated everything I saw in videos or other threads it still wouldnt work. Is this maybe some kind of render pipeline issue?

    The video I tried to replicate is:

    The thread I read is: https://forum.unity.com/threads/2d-pixel-perfect-with-smooth-camera.906122/
     
  4. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    my first tip would be dont use cinemachine if you are trying to make pixel perfect the movements are too smooth

    if you check the original pixel art games they never did super smooth and subtle camera motions because of of all the sub pixel positions issues
     
  5. GreenPhotonRays

    GreenPhotonRays

    Joined:
    Feb 25, 2022
    Posts:
    11
    Thanks for your ideas!

    I think I figured some kind of workaround:

    I used no cinemachine as you said and used my old camera follow script (it had the same issues).
    Then I applied the pixel perfect component.
    This looked very choppy, but I took an example at stardew valley.
    If you own or have footage from stardew valley you notice, that the camera is not perfectly on the player, but has very liitle of smoothing.
    I applied this kind of smoothing for my game and now the choppyness is (almost) not noticable.

    It is not perfect, because Ive seen many devlogs in which people have this "perfect solution" but dont explain it, but it works for now.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    If you're following a Transform being moved via a Rigidbody2D then you'll need to ensure that interpolation is on in the Rigidbody2D settings so it's updated per-frame and not per-fixed-update. Either that or run physics per-frame.
     
  7. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    nice =)

    I will give you one last thing to note, stardew valley is not pixel perfect

    dont try too hard to get pixel perfect, if you are happy with how stardew valley looks

    chasing pixel perfect will just create headaches for you, when almost no one does pixel perfect nowadays
     
  8. GreenPhotonRays

    GreenPhotonRays

    Joined:
    Feb 25, 2022
    Posts:
    11
    Thank you, but Im at this problem for literal days, so I've tried A LOT (including your Ideas). Ive even seen your video "Unity 2D Physics - Per-Frame Simulation Sub-Stepping".

    either way, Thanks!
     
    MelvMay likes this.
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Yeah, sub-stepping won't have anything to do with this. I guess you're saying then that you are using Rigidbody2D with interpolation on the GO Transform you're tracking?

    Would be useful to see your issue and what you're doing.
     
  10. GreenPhotonRays

    GreenPhotonRays

    Joined:
    Feb 25, 2022
    Posts:
    11
    yeah, ive got this as my player if you want an overview from it player.PNG
     
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Looks good. And you're not modifying the Transform here at all correct?

    If not, as a test and assuming you've not got anything in FixedUpdate that can cause issues, if you temporarily switch the SimulationMode to "Update", does that sovle the issue?
     
  12. GreenPhotonRays

    GreenPhotonRays

    Joined:
    Feb 25, 2022
    Posts:
    11
    I tried it and doesnt work that well. Can it be, that some project settings or the URP have something to do with the problem?
    PS: If we dont come to a solution, Im fine with what I got. As said above I have a rustical solution that works for now.
     
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    I don't know what the problem is. I've not seen the problem, only a rough description of it. All I was trying to do with discount physics i.e. reduce your potential problem domain.

    Not using a Rigidbody2D and just modifying the Transform position would tell you that too but if you're fine with what you've got then that's good too.