#Character blur/stutter when moving

1 messages · Page 1 of 1 (latest)

jade summit
#

Hi all!!

There's a weird stutter when my character moves (which on higher FPS/refresh rates makes it look super blurry) and I'm curious just to why it is/how to prevent it from happening. I've got a simple movement script set up:

// PlayerMovement.cs
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5f;
    private Rigidbody2D rb;
    private Vector2 moveInput;

    public float playerX = 0f;
    public float playerY = 0f;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        rb.linearVelocity = moveInput * moveSpeed;

        playerX = rb.position.x;
        playerY = rb.position.y;
    }

    public void Move(InputAction.CallbackContext context)
    {
        moveInput = context.ReadValue<Vector2>();
    }
}

And a "smooth" camera follow

// PlayerFollow.cs
using UnityEngine;

public class PlayerFollow : MonoBehaviour
{
    public PlayerMovement playerMove;
    public float smoothSpeed = 10f;

    void LateUpdate()
    {
        if (playerMove == null)
        {
            return;
        }

        Vector3 targetPosition = new Vector3(playerMove.playerX, playerMove.playerY, -10f);
        transform.position = Vector3.Lerp(transform.position, targetPosition, smoothSpeed * Time.deltaTime);
    }
}

Could it be the camera LateUpdate that's causing the issue?

#

oh shoot

#

uploaded wrong thing

thick apex
#

is you rigidbody interpolated

jade summit
thick apex
#

also for pixelart, make sure you have a pixel perfect camera

jade summit
jade summit
thick apex
#

yes

#

it's a component you add to the camera gameobject (not replacing the existing camera)

jade summit
#

what does that change?

thick apex
#

it makes the camera aware of pixel alignment

jade summit
#

also, what does interpolation do?

thick apex
#

rigidbodies update on the physics tick/fixed time step, aka FixedUpdate
interpolation in math is the process of finding a continuous change between 2 discrete points
computers are inherently discrete, the discrete points in question here are the rigidbody's state between 2 fixed updates
interpolation lets the rigidbody smoothly transition between them when the graphics update, Update, is more frequent than the physics tick

jade summit
#

ahh

#

so the stutter was just the update between ticks being inconsistent/not as fast?

thick apex
#

that's my best guess given the available info

#

(though keep in mind that sometimes multiple things can contribute to stutter, and fixing one thing might not make the stutter fully go away)

#

having the camera in LateUpdate rather than Update already solves one of the possible issues

#

i don't recall if the lack of a pixel perfect camera can also cause stuttering, but i do remember it being related to camera stuff

jade summit
#

ohhh alright

#

okay, tank you!!

thick apex
#

also in case you haven't - for pixel art, make sure to set filter point, compression none, and an appropriate ppu on the texture import settings