I am making a top down 2d game where the player needs to fight off hordes of enemies.
These are the lines of code that plays the attack animation:
if Input.is_action_just_pressed("attack"):
$sword_tween.interpolate_property($ColorRect, "rect_rotation", 0, -64, .4, Tween.TRANS_BACK, Tween.EASE_IN_OUT)
$sword_tween.start()
i have written the above lines of code inside physics process function.
i have an area2d with the player node that checks if the enemy is in front of the player.
This is how i am registering a hit, if a body enters the area 2d it checks if the attack tween is playing then it checks if the body has a method called hit, if it does it calls the method.
func _on_Sword_body_entered(body):
if $sword_tween.is_active():
if body.has_method("hit"):
body.hit()
Then inside the enemy script i just use the queue free method inside hit function
func hit():
print("enemy hit")
queue_free()
But when i run the scene the hits don't register while the player is standing still

and it works when the player is moving

One thing i have noticed is that it works fine when i am using is_action_pressed method instead of is_action_just_pressed, but i don't want the player spamming the attacks. i tried using a timer with is_action_pressed but no luck. What am i doing wrong? please help!