I have been trying to make a character movement in Godot 4.1 and when I move the player up or down, the walking animations play, however when I move left and right, only the idle animations play?
(I’m using a sprite3D in a 3D scene, I don’t know if this is important or not.)
Here is my code in gdscript:
extends CharacterBody3D
const SPEED = 2
var facing = "Front"
var walking = 0
# Called when the node enters the scene tree for the first time.
func _ready():
pass
# Movement
func _physics_process(delta):
if Input.is_action_pressed("right") and Input.is_action_pressed("left"):
velocity.x = 0
walking = 0
elif Input.is_action_pressed("right"):
velocity.x = SPEED
facing = "Right"
walking = 1
elif Input.is_action_pressed("left"):
velocity.x = -SPEED
facing = "Left"
walking = 1
else:
velocity.x = 0
walking = 0
if Input.is_action_pressed("up") and Input.is_action_pressed("down"):
velocity.z = 0
walking = 0
elif Input.is_action_pressed("up"):
velocity.z = -SPEED
facing = "Back"
walking = 1
elif Input.is_action_pressed("down"):
velocity.z = SPEED
facing = "Front"
walking = 1
else:
velocity.z = 0
walking = 0
move_and_slide()
# Animations
func _process(delta):
if walking == 1:
$AnimationPlayer.play("Walking" + facing)
else:
$AnimationPlayer.play("Idle" + facing)
I have checked multiple times, and the animations are named correctly.