Godot Version
4.3
Question
so im trying to make an rpg platformer for my first game and ive hit a roadblock with the attack gravity run idle and jump all works but I cant make the attack animation play cause I think the idle run and jump is overridng it how do I fix it ive already tried a variable but the animations just keep playing regardless can someone help? (also swing is printing) extends CharacterBody2D
var swinging = false
const SPEED = 130
const JUMP_VELOCITY = -300
@onready var animated_sprite = $AnimatedSprite2D
func _physics_process(delta: float) → void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
if Input.is_action_just_pressed("swing"):
swinging = true
animated_sprite.play("Swing 1")
await get_tree().create_timer(0.6).timeout
swinging = false
print("swing")
# direction can be -1 0 1
var direction := Input.get_axis("left", "right")
if direction > 0:
animated_sprite.flip_h = false
elif direction < 0:
animated_sprite.flip_h = true
#animations
if is_on_floor():
if direction == 0 and swinging == false:
animated_sprite.play("idle")
else:
animated_sprite.play("run")
elif !is_on_floor():
animated_sprite.play("jump")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()