#Blurry sprite animations when moving

10 messages · Page 1 of 1 (latest)

gusty seal
#

When i move my character with an animatedsprite2d, the animations get blurrier as speed increases, is there a way to fix this issue?
example video linked

edgy heart
#

Post the movement code

gusty seal
#

@export var speedbase = 70 
@export var runmultiplier = 1.5
@onready var animation = get_node("AnimatedSprite2D") # references the animatedsprtite2d


func _physics_process(delta):
    velocity = Vector2.ZERO #resets velocity each frame
    var diff = speedbase
    
    if Input.is_action_pressed("run"):
        diff = speedbase * runmultiplier # if shift is pressed as well then it multiplies speedbase by the runmultiplier
    get_input(diff)
    animationupdate()
    
        
func get_input(diff):
    
    var input_direction = Input.get_vector("left", "right", "up", "down")
     
    velocity = input_direction * diff
    
    move_and_slide() # ensures smooth movement
    
        
func animationupdate(): # changes the animation based on the current state#
    
    
    if round(sqrt(velocity.x * velocity.x + velocity.y * velocity.y)) != 0 and round(sqrt(velocity.x * velocity.x + velocity.y * velocity.y)) < (speedbase * runmultiplier): # if the player NOT is standing still and is moving at a speed slower than running
        animation.play("walk")
    if round(sqrt(velocity.x * velocity.x + velocity.y * velocity.y)) <= 0.5: # 0.5 is a buffer
        animation.play("idle")
    if round(sqrt(velocity.x * velocity.x + velocity.y * velocity.y)) >= speedbase * runmultiplier * 0.8: #if the player is moving >= the run speed then run animation plays
        if animation.animation != "run":
            animation.play("run") ```
#

discord formatting messed up the indentations

#

ill send an ss later

edgy heart
#

velocity = Vector2.ZERO #resets velocity each frame is this really needed?

gusty seal
#

hmm

#

probably not ig, looking back at it

#

ive removed it and the issue still happens though

raven eagle
#

the bluriness comes from a combination of the character movement and the camera movement. If you play the video slowly you can see sometimes the character moves 1px, sometimes it moves 2px, and the camera following moves at variable speeds as well.

Resetting velocity each frame would affect that, as would any other pixel snapping code you have.

You need to maintain the speed/velocity as sub pixel values and not round/snap on each update, so that the movement can accumulate over multiple frames.

The camera movement is also tricky to fix as it's tracking at a different speed, but you need to take a similar approach, not rounding the speed each update