My Attack animation played only one frame
How do I Fix it?
Hers the Code:
extends CharacterBody2D
class_name Player
@onready var animation = $AnimatedSprite2D
@onready var sprite = $Sprite2D
const SPEED = 200.0
const JUMP_VELOCITY = -700.0
@onready var sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@export var attacking = false
func _process(_delta: float) → void:
if Input.is_action_just_pressed(“attacks”):
attack()
func _physics_process(delta):
if Input.is_action_pressed(“left”) && attacking == false:
animation.scale.x = abs(animation.scale.x) * -1
if Input.is_action_pressed(“right”) && attacking == false:
animation.scale.x = abs(animation.scale.x)
# Animations
if (velocity.x > 0 || velocity.x < 1):
sprite_2d.animation = "walking"
else:
sprite_2d.animation = "default"
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
sprite_2d.animation = "jump"
# Handle jump.
if Input.is_action_just_pressed("jump") && is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
update_animation()
move_and_slide()
sprite_2d.flip_h = false
func attack():
var overlapping_objects = $Attacking.get_overlapping_areas()
for area in overlapping_objects:
var _parent = area.get_parent()
print("attacking")
attacking = true
animation.play("attacking");
if sprite_2d.animation == "attacking":
attacking = false
func update_animation():
if !attacking:
if velocity.x != 0:
animation.play(“walking”)
else:
animation.play(“default”)
if velocity.y < 0:
animation.play("jump")
func _on_animated_sprite_2d_animation_finished():
if $AnimatedSprite2D.animation == “attacking”:
attacking = false;
I Tried everything and it makes me want to give up