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