Godot Version
v4.5.1.stable.official
Question
I've been trying to make a crouching animation on my player script but it only plays the first frame of animation, wich i realized is because my idle animation is interfering. I’m new to coding and haven’t been able to find a suitable workaround.
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
func _physics_process(delta: float) -> void:
# Get the input direction and handle the movement/deceleration.
var direction := Input.get_axis("walk_back", "walk_forward")
var crouch := Input.get_action_raw_strength("crouch") and is_on_floor()
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
animated_sprite.play("jump")
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
#Handle movement.
if direction and is_on_floor():
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
#Walking animations here.
if is_on_floor():
if direction == 0 :
animated_sprite.play("Idle")
if direction > 0:
animated_sprite.play("walk forward")
if direction < 0:
animated_sprite.play("walk back")
#How do i make you crouch?
if crouch:
animated_sprite.play("crouch")
print("im crouch'd trust")
move_and_slide()