Smooth Movement vs Pixel Perfect Sprites Need Help!

Hello Unity Forum,

(I really need help so I’m going to go into the best detail I can.)

I’ve spent about 10-15 hours on this over the last two days and I’m simply stuck between a rock and a hard spot at this point, and I’d rather just have the best of both worlds. Either the sprites in the project I started have to be blurred by the bilinear filter mode for smooth movement, or with point (no filter) I can achieve pixel perfect looking sprites with Unity Asset Store - The Best Assets for Game Making BUT the downside is that the movement becomes much more discrete looking, you can sort of see the pixels snap into place after each movement.

I’ll talk about both solutions and hopefully someone can help me out.

Before we get into it here’s the sprite sheet I’m working with –

And the script for movement in case that matters to someone –

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
{
    private Transform _Transform;
    private Rigidbody2D _Rigidbody2D;
    private SpriteRenderer _SpriteRender;
    [SerializeField] private Sprite[] _sprite = new Sprite[3]; //down, up, right
    [SerializeField] private float speed = 3f;
    private Vector2 moveVector;

    void Start()
    {
        _Transform = GetComponent<Transform>();
        _Rigidbody2D = GetComponent<Rigidbody2D>();
        _SpriteRender = GetComponentInChildren<SpriteRenderer>();
    }
  
    void Update()
    {
        float xInput = Input.GetAxisRaw("Horizontal"), yInput = Input.GetAxisRaw("Vertical");


        if (xInput == 1 || xInput == -1)
        {
            _SpriteRender.sprite = _sprite[2];
            if (xInput == 1)
                _SpriteRender.flipX = false;
            if (xInput == -1)
                _SpriteRender.flipX = true;
        }
        if (yInput == -1)
            _SpriteRender.sprite = _sprite[0];
        if (yInput == 1)
            _SpriteRender.sprite = _sprite[1];


        moveVector = new Vector2(xInput, yInput);
        //_Rigidbody2D.velocity = moveVector * speed;
    }
  
    void FixedUpdate()
    {
        MoveRigidBody();
    }
   

    void MoveRigidBody()
    {
        _Rigidbody2D.velocity = moveVector * speed;
    }
}

Solution (1) : Smooth but Blur
Build – https://drive.google.com/file/d/0BxVy31mpcFlXZGwzM285ZWtycjQ/view?usp=sharing

This is probably the better of the two solutions except besides the blur it has one obvious flaw I’ll get into later.

Firstly, here are the settings I’m using on the sprites –
2449905--168212--BlurButSmoothSettings.PNG

and here is the point filter version of the sprite
2449905--168211--BlurButSmoothBLURRY.PNG

Importantly the PPU is 32 and the camera is a size 12 and the resolution is 1024x768.

The blur is annoying but acceptable if not for the fact that depending on where the sprite is on the screen it goes between crisp and blur. I have no idea why, here’s an example.

From This: (Crispy) 2449905--168205--BlurButSmoothCrisp.PNG to this (Blurry)2449905--168211--BlurButSmoothBLURRY.PNG with only a side step.

I don’t like it being blurry but if it has to be for smooth movement I’d make the sacrifice but it at least needs to be consistently blurry.


Solution (2) : Crisp but Stutter
Build – https://drive.google.com/file/d/0BxVy31mpcFlXUWpJOUtNdWFGX1E/view?usp=sharing

If I could simply remove the small stutter this would be the perfect solution I prioritize smooth movement over crisp sprites.

With this solution I switch the filter mode to point (no filter)

And suddenly like magic the sprite becomes crispy and everything gets hopeful until I start the build and begin to move and look closely at the sprite. The movement seems a bit janky, like there interpolation becomes bad, it’s a consistent jank but it’s certainly there. It becomes more obvious when you filter the sprite then put both side by side, with a blur it is smooth, without there is bad interpolation.

I purchased Pixel Perfect by Pixelatto hoping that would help but the stutter still seems to be there with the pixel perfect script on the sprite and camera.


Extras:
Just in case it matters here are the quality settings –

I’ve tried playing with the camera size, the PPU, the pixel snap material, the compression size, the format, and finally I’ve played around with the mip map setting.

Hopefully I didn’t miss anything, I’ve read just about every other forum on this as well.

Thanks for any help you can contribute, I really appreciate it.

2449905--168204--CharactersSpritesheet.png

I’d like to bump this once to see if there’s any suggestions and to add a poor fix to the problem. I’ve introduced a new script which will turn on the bilinear filter while moving on the x axis. It still makes the sprite very blurry but I think it’s the best option I have so far. A huge disadvantage of this is that any sprites on the spritesheet will be blurred during this so the sprites need to be cut into separate spritesheets.

Here’s the script

using UnityEngine;
using System.Collections;

public class FilterMove : MonoBehaviour
{
    private Sprite _sprite;
    private Rigidbody2D _rigidBody2D;

    void Start ()
    {
        _sprite = this.gameObject.GetComponent<SpriteRenderer>().sprite;
        _rigidBody2D = this.gameObject.GetComponentInParent<Rigidbody2D>();
    }
   
    void Update ()
    {
        if (_rigidBody2D.velocity.x != 0)
            _sprite.texture.filterMode = FilterMode.Bilinear;
        else
            _sprite.texture.filterMode = FilterMode.Point;
    }
}

I managed to get a pixel-perfect look, but my game has a completely static camera, so if yours moves, you’ll likely need to have something in your camera’s update that rounds its position to the nearest something (I don’t know what exactly). Anyways, this is how I set it up:

  • Point filtering
  • No mipmaps
  • Disable anti-aliasing
  • Sprites imported at 32 px/unit
  • Camera orthographic size: (Screen.height / 2 / pxPerUnit)
  • Camera position: (0.01, 0); I absolutely hate this, but for some reason, my sprites don’t quite display properly when the camera is at (0, 0).
  • Resolution: 1366x768 (my laptop’s resolution)
  • Sprites have a material with PixelSnap enabled
  • Sprite sheet atlases are all power of 2 in size. I think this may be unnecessary though…
  • What is important (I think) is that each sprite on the sheet is drawn within a power of 2-sized cell. So if your sprite is 18x20, you’ll have to draw it at the centre of a 32x32 cell.

Also note that since upgrading to Unity 5 my moving sprites do not appear pixel-perfect in the editor unless I either remove the PixelSnap material or change the display resolution to Free Aspect. In builds of the game, however builds of the game will display properly with the above-listed settings.

One last thing is that I have some collision objects with “Continuous” collision detection. These objects look distorted with PixelSnap material, so I use the default for them. I don’t expect them to look pixel-perfect anyways because they are round and are often rolling around (rotation is always going to cause some distortion).

Anyways, maybe that’ll give you a few more things to play around with.

1 Like

Two observations…

(1) Make sure you fully understand Unity Blog .
(2) When checking animation smoothness, always do it in an executable built for the target device. Don’t play it in the editor or through Unity Remote. The editor seems to introduce shuddering effects.

This is similar to Tile Map Tearing Problems - Unity Engine - Unity Discussions .

1 Like

On top of jester-race’s answer, I’ll dig a bit deeper on setting the camera’s orthographic size.

In order to achieve a pixel-perfect result, each sprite pixel must be rendered to an integer multiple of screen pixels. Having this in mind, you have to make the correct calculations and adjust the camera’s size to achieve that. To achieve that, you should know the camera’s render size, your asset’s pixels per unit and chose a desired camera size.

I have created a simple free camera script that just these calculations for you. You can get it for free from the asset store and read a deeper explanation of the problem on my blog post.

Check out this HTML5 demo. If you switch off the pixel perfect mode, you’ll notice the same artifacts that you describe.