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 Sprite moving 1/2 pixel when using pixel perfect camera (solved)

Discussion in '2D' started by Oshigawa, Jul 25, 2023.

  1. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I have a texture set to 100 pixels per unit and pixel perfect camera set to 100 asses pixels per unit, yet the prefabs move 1/2 of the pixel on runtime unless i set pixels per unit of the texture to 200 which doesn't make sense.

    Current pixel ratio is 1:1

    Any ideas on this one?

     
    Last edited: Jul 25, 2023
  2. MaxwellTan

    MaxwellTan

    Unity Technologies

    Joined:
    Mar 3, 2022
    Posts:
    73
    Hi, may I know what screen resolution are you looking at?
     
  3. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    What configuration of pixel perfect camera are you using?

    Pixel perfect camera will do nothing to the movement if you are not using either upscale or pixel snapping options. In such configs you can position the sprites freely which might look like moving by half a sprite pixel depending on rest of the settings, while what's actually happening that it is moving by 1 screen pixel possibly amplified by zoom settings.

    If you are using pixel snapping be very careful with sprites that don't have even dimensions (doesn't divide by 2). Those can also easily cause unwanted 0.5 pixel offsets.
     
  4. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    640x360 in the viewport, reference resolution is the same.
     
  5. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    It's set to pixel snapping, the sprites are dividable by 2.
     
  6. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    Few more random guesses.

    * Are you using a sprite renderer or gui components to display the sprite? If you are using sprite renderer, all good. But if you are using gui components (Image or other stuff that goes under canvas) that's a completely different story.
    * Does the spriterender and all it's parents have the scale set to 1,1,1 ?

    How exactly are you observing the problem? Does the rendered sprite actually move in the increments of 0.5 asset pixels when you change the transform position? Or are you only observing 0.5 pixel offset between different sprites?
     
  7. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    @karliss_coldwild

    Sprite renderer, everything has 1, 1, 1 scale. Sprite moves in 0.5 increments when i change the position (drag and drop via script) in both editor and on runtime.

    Must be missing something.

    Actually, not so sure about editor, gotta check it out.
     
    Last edited: Jul 25, 2023
  8. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    It's all good in the editor, runtime causes issues. Maybe i should round the position to two decimals, i'll try it out.
     
    Last edited: Jul 26, 2023
  9. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I think i can manage to round the second decimal to an even nearest number when moving the object and fix it like that, but i'm still oblivious to why isn't it rendered properly in the first place, i guess that's the point of the camera, to snap round the visual snapping of the position.
     
  10. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I imported good old Pro Camera 2D from Luis Pedro Fonseca works like a charm, not this crap.