The player in my game has an attack animation with 2 swings. I have implemented the damage dealing function, but the player dealt all the damage on the first swing. Thus I decided to create another function and add Key Frames to the animation to deal half the damage in each swing. The problem now, however, is that the player only deals damage on the second swing. I figured out that both hits are actually detected, just that damage is not dealt on the first hit.
This is the code I wrote:
The code with the # before it is the code I don’t really need because I already have the _on_attack_hit() function.
#func _on_sword_hit_area_entered(area):
# if area.is_in_group("hurtbox"):
# print("Hit: ", area.name)
# area.get_parent().call("take_damage", GlobalVariables.player_attack_damage)
func _on_attack_hit():
%SwordHit.monitoring = true # Force enable
await get_tree().physics_frame # Wait for collision detection
for area in %SwordHit.get_overlapping_areas(): # Check ALL current overlaps
if area.is_in_group("hurtbox"):
var split_damage = GlobalVariables.player_attack_damage / 2.0
area.get_parent().call("take_damage", split_damage) # Half damage per swing
print("Timed hit at frame: ", $AnimationPlayer.current_animation_position)
If there is any other info you need to help me solve it, please say so .