Hey everyone, so I can't seem to have animated sprite and movement work together in the same code. I want my player to be able to animate in different directions when he walks. Here is my code. Thanks in advanced

extends Kinematicbody2D
const FRICTION = 10
const ACCELERATION = 10
const MAX_SPEED = 100

var velocity = Vector2.ZERO


func _process(delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")i
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()

if input_vector != Vector2.ZERO:
 
 velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION)
else:

 velocity = velocity.move_toward(Vector2.ZERO, FRICTION)

move_and_slide(velocity)


onready var _animated_sprite = $AnimatedSprite

if Input.is_action_pressed("ui_right"):
 _animated_sprite.play("right")
else:
  _animated_sprite.stop()

if Input.is_action_pressed("ui_left"):
 _animated_sprite.play("left")
else:
 _animated_sprite.stop()
 
if Input.is_action_pressed("ui_up"):
 _animated_sprite.play("back")
else:
 _animated_sprite.stop()
 
if Input.is_action_pressed("ui_down"):
 _animated_sprite.play("front")
 
else:
 _animated_sprite.stop()
  • So what exactly is the problem? I guess your character doesn't animate at all on button press? Because from what I see your if Input.is_action_pressed() conditions nullify each other. You first check if ui_right is pressed, if not stop animating. Then you check if ui_left is pressed. If not stop animating. But whenever you press ui_right it's very likely you aren't pressing ui_left so ui_right animation will be stopped by ui_left condition.

So what exactly is the problem? I guess your character doesn't animate at all on button press? Because from what I see your if Input.is_action_pressed() conditions nullify each other. You first check if ui_right is pressed, if not stop animating. Then you check if ui_left is pressed. If not stop animating. But whenever you press ui_right it's very likely you aren't pressing ui_left so ui_right animation will be stopped by ui_left condition.