Can't get attack collision shape hitbox to enable when attack button is pressed.

I’m trying to make a 2 player 1v1 fighting game (very basic, just trying to get the hang of Godot by doing something small). I have the collision shape set up for the hitbox, and i have coded it to play the animation when the attack button is pressed. I have the attack animation to have the hitbox enable when it is pressed and after 1 second disable it. When I play it in the player though, the hitbox never is enabled. Any ideas why this is happening?

I also want the hitbox to flip in the direction of the character when they move but not sure how, it remains static no matter where the character is facing. I’m all ears on a solution for that, too! The script I have so far is below!

const SPEED = 900.0
const JUMP_VELOCITY = -1500.0
@onready var health_bar = $AnimatedSprite2D/HealthBar
var hp = 5

func _physics_process(delta: float) → void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# 1. Start the attack if the button is pressed and we aren’t already attacking

# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = JUMP_VELOCITY

# Get the input directions -1. 0. 1
var direction := Input.get_axis("move_left", "move_right")

#Play Attack animations
if Input.is_action_just_pressed("attack"):
	$AnimatedSprite2D.play("Attack") 
	await $AnimatedSprite2D.animation_finished
	$AnimatedSprite2D.play("Idle")

#FLIP The sprite
if direction > 0:
	$AnimatedSprite2D.flip_h = false
elif direction < 0:
	$AnimatedSprite2D.flip_h = true 
# Apply to movement
if direction:
	velocity.x = direction * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()

func _on_Attack_Area_entered(area):
if area.is_in_group(“hurtbox”):
hp = -1

I am not sure if you solved the problem already. But, from the script alone, I don’t think the issue is here. The hitbox is never enabled in code, so I’m assuming you’re using an AnimationPlayer or sprite animation track to toggle the CollisionShape2D.disabled property.

Try enabling the hitbox from code temporarily to verify it works:

$AttackArea/CollisionShape2D.disabled = false
await get_tree().create_timer(0.2).timeout
$AttackArea/CollisionShape2D.disabled = true

If this works, then the problem is almost certainly with the animation track rather than your script.

For flipping the hitbox, if it’s a child of AnimatedSprite2D, it should flip automatically with the sprite. If it’s a sibling or elsewhere in the scene tree, you’ll need to mirror its position yourself, for example:

if direction > 0:
    $AttackArea.position.x = abs($AttackArea.position.x)
elif direction < 0:
    $AttackArea.position.x = -abs($AttackArea.position.x)

AnimatedSprite2D only handles the animation. It won’t enable or disable your hitbox automatically, so you’ll need to do that in code (or with an AnimationPlayer track).

Something like:

if Input.is_action_just_pressed("attack"):
	$AnimatedSprite2D.play("Attack")
	$AttackArea/CollisionShape2D.disabled = false
	await $AnimatedSprite2D.animation_finished
	$AttackArea/CollisionShape2D.disabled = true
	$AnimatedSprite2D.play("Idle")

Also, flip_h only flips the sprite. Child nodes stay where they are, so you’ll need to mirror the hitbox position yourself:

if direction > 0:
	$AnimatedSprite2D.flip_h = false
	$AttackArea.position.x = abs($AttackArea.position.x)
elif direction < 0:
	$AnimatedSprite2D.flip_h = true
	$AttackArea.position.x = -abs($AttackArea.position.x)

(Replace $AttackArea with your current node)