Godot Version
v4.3.stable.official[77dcf97d8]
Question
While implementing movement to my player character, i only made animations for the cardinal directions. Those work great but I’m trying to make it so when holding W and A or W and D, the animation for walking north plays, and also the same thing when going south. However, when the player walks diagonally, the animation freezes on the first frame.
extends CharacterBody2D
@export var speed = 400
@onready var _animated_sprite = $PlayerCharacter
func _process(_delta):
if Input.is_action_pressed("right"): #idle veified
_animated_sprite.play("WalkE")
if Input.is_action_pressed("left"): #idle verified
_animated_sprite.play("WalkW")
if Input.is_action_pressed("up"): #idle verified
_animated_sprite.play("WalkN")
if Input.is_action_pressed("up") and Input.is_action_pressed("left"):#idle verified
_animated_sprite.play("WalkN")
if Input.is_action_pressed("up") and Input.is_action_pressed("right"):#idle verified
_animated_sprite.play("WalkN")
if Input.is_action_pressed("down"): #idle verified
_animated_sprite.play("WalkS")
if Input.is_action_pressed("down") and Input.is_action_pressed("left"):#idle verified
_animated_sprite.play("WalkS")
if Input.is_action_pressed("down") and Input.is_action_pressed("right"):#idle verified
_animated_sprite.play("WalkS")
if not (Input.is_action_pressed("right") or Input.is_action_pressed("left") or Input.is_action_pressed("up") or Input.is_action_pressed("down")):
_animated_sprite.play("Idle")
func get_input():
var input_direction = Input.get_vector("left", "right", "up", "down")
velocity = input_direction * speed
func _physics_process(delta):
get_input()
move_and_slide()