Need help Please

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 :confused:

Do like this:

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");
    await get_tree().create_timer(0.7).timeout
    attacking = false

Change the 0.7 with the duration of attacking animation.

1 Like

Thx But now its just still one frame and a walking animation
(I’m using The AnimatedSprite2D btw sorry if I didn’t remind you about what I use earlier)

Try to move it at the end of the physics process function.

And please put the codes in proper code format:

``` I used this symbol thrice for it and can paste my codes here ```

can you show me the example please?

Example? I said just move the code at the end of the physics process. And if it not works, then write your codes in proper format as I mentioned, in this forum (topic).

Ah ok thx

1 Like

well I tried :confused: it didnt work

Your codes does not works? Then please can you put the codes in proper format as I mentioned in your topic.

I did and it didnt work

The code format? Do you done it like this?

``` Write the symbol at first to start the code format and then end it similarly ```

yes but im sorry to say this it didnt work
idk what code format is (sorry if i didnt say this in the first place :confused: that was stupid of me)

1 Like

I have this issue where i have a sprite and background connected together in a way like a parent/child nodes but i cant find a way to remove them from eachother due to them being one node.