I have a problem with damage registration, i call check_overlapping_areas method at 1 keyframe in AnimationPlayer’s animation, but it deal damage first 3 times, later 2 times always. Damage realize by global signal enemy_got_damage, so:
weapon script to deal damage (only func):
func check_overlapping_areas():
await get_tree().process_frame
var overlapping_areas = $AttackArea.get_overlapping_areas()
var enemies_group = get_tree().get_nodes_in_group("Enemies_Group")
var enemies_group_size = enemies_group.size()
var i = 0
while i < enemies_group_size:
if enemies_group[i] in overlapping_areas:
GlobalScript.enemy_got_damage.emit(DAMAGE, enemies_group[i])
i += 1
if i >= enemies_group_size:
i = 0
break
enemy’s script to receiving damage (only func, .callable() for signal in _ready() func):
Weapon start animation, from 0.15s to 0.3s weapon enable collision for area, all other times of animation collision disable. Keyframe to func check_overlapping_areas is on 0.151s only
func check_overlapping_areas():
await get_tree().process_frame
var overlapping_areas = $AttackArea.get_overlapping_areas()
var enemies_group = get_tree().get_nodes_in_group("Enemies_Group")
var enemies_group_size = enemies_group.size()
var i = 0
while i < enemies_group_size:
print(2)
if enemies_group[i] in overlapping_areas:
print(1)
GlobalScript.enemy_got_damage.emit(DAMAGE, enemies_group[i])
i += 1
if i >= enemies_group_size:
print(3)
i = 0
break
func check_overlapping_areas():
await get_tree().process_frame
var overlapping_areas = $AttackArea.get_overlapping_areas()
var enemies_group = get_tree().get_nodes_in_group("Enemies_Group")
var enemies_group_size = enemies_group.size()
var i = 0
while i < enemies_group_size:
print(enemies_group, enemies_group_size, overlapping_areas)
if enemies_group[i] in overlapping_areas:
print(enemies_group[i])
GlobalScript.enemy_got_damage.emit(DAMAGE, enemies_group[i])
i += 1
if i >= enemies_group_size:
i = 0
break
If on_enemy_got_damage() is connected to the global signal for each enemy, then your code will call it on all enemies whenever any enemy gets hit. So if you have 3 enemies in total, on_enemy_got_damage() will run on all of them.
You may think about using a different approach to handle/organize signals, but a quick fix would be to check if the enemy argument you got in the signal handler is actually the enemy that the script is attached to, and apply the damage only if that’s true.