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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Smooth pixelart camera and pixelperfect UI?

Discussion in '2D' started by Dead1nside, Dec 30, 2018.

  1. Dead1nside

    Dead1nside

    Joined:
    Nov 28, 2018
    Posts:
    15
    I have a problem with the camera in my pixel art game. When the camera does not move, everything is fine, but if the camera is following the player, other objects jams on the stage. I have read many threads in various forums, but answers didn't help or were mutually exclusive. So I wanted to ask what is the right way to make the camera work smoothly. I use cinemamachine and Pixel Perfect Camera 2D (from unity package). I also wanted to ask if it is possible for the UI to be Pixel Perfect. If so, how should I set a canvas? Or should I just create "ui" from sprites on scene?
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @deadpixelpl

    Hi, what do you mean by "other objects jams on the stage."

    It sounds like if you make your camera follow player, other objects stop moving in worlds space. Or is it something else?
     
  3. Dead1nside

    Dead1nside

    Joined:
    Nov 28, 2018
    Posts:
    15
    They are moving but in ... "laggy" way.
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    How do you move them, and how do you move the camera?
     
  5. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    I think the UI part of question could be another question...

    But anyway.

    Have you checked the manual? First google search for pixel perfect UI is (2018.3):
    https://docs.unity3d.com/ScriptReference/Canvas-pixelPerfect.html

    I haven't yet used 2018.3 so I can't say if this is helpful.

    I think canvas based UI can be pixel perfect. To me it sounds like you haven't even tested it yet. Try doing it first and you'll see how far you can get with all needed components.

    I'm going to use such setup (possibly), it's doable it seems, of course more work than slapping elements on screen and some things should be considered regarding resolution and aspect ratios, how elements are snapped to grid etc.

    Here's a test I made.



    And yes, it's not probably looking OK in browser, but if you download the picture, you'll see it as it is supposed to be.

    I think it's pretty much what I need. Panel pixels are at least exactly on the grid.
     
  6. Dead1nside

    Dead1nside

    Joined:
    Nov 28, 2018
    Posts:
    15
    I move other objects (enemies) by this script:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class EnemyController : MonoBehaviour
    4. {
    5.  
    6.     public Transform target;
    7.     public float speed = 3f;
    8.  
    9.     void Update()
    10.     {
    11.         transform.position = Vector2.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime);
    12.     }
    13. }
    14.  
    Enemy just always go to player location.

    I move camera by Cinemachine
    upload_2018-12-30_19-54-11.png

    I probably misspoke when I spoke about UI. I meant a different size of pixel blocks in UI elements when I'm scalling screen size. Here's example:
    upload_2018-12-30_20-9-41.png
    Size of these pixels is not uniform. It is difficult for me to describe a problem, which I don't fully understand, in not my native language.

    Here's my canvas settings:
    upload_2018-12-30_20-33-5.png
     
    Last edited: Dec 30, 2018
  7. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @deadpixelpl

    Pixels / UI - try to match your sprite Pixels Per Unit and Canvas Reference Pixels per Unit - Naturally, UI elements must be full int values, like x40,y21 for position, width and so on - otherwise you are between pixels.
     
  8. Dead1nside

    Dead1nside

    Joined:
    Nov 28, 2018
    Posts:
    15
    I set same PPU (16) for sprites and for reference PPU in canvas. When I'm adding image to my UI I just click "Set Native Size"

    One of my sprite setting in canvas example:
    upload_2018-12-30_21-34-32.png
     
  9. Daniel_Abeleira

    Daniel_Abeleira

    Joined:
    Oct 16, 2018
    Posts:
    7
    I know this is very old but I'm also looking for a way to make all "pixels" in my screen the same dimensions, so that there are no overlapping pixels at all, neither in the game world nor in the UI.
     
  10. Daniel_Abeleira

    Daniel_Abeleira

    Joined:
    Oct 16, 2018
    Posts:
    7