after for more digging, i did found source of the prolem.
its because of the second type of enemy that instanced at the third wave.
i did instance only that enemy and did it one by one and count every instanced node and when they are killed.
its allways instance 10 of it and thats right, but time to time kill count return as +1, like
enemy 4 instance : 1
enemy 4 instance : 2
enemy 4 instance : 3
enemy 4 instance : 4
enemy 4 instance : 5
enemy 4 killed : 1
enemy 4 killed : 2
enemy 4 killed : 3
enemy 4 instance : 6
enemy 4 instance : 7
enemy 4 instance : 8
enemy 4 killed : 4
enemy 4 instance : 9
enemy 4 killed : 5
enemy 4 instance : 10
enemy 4 killed : 6
enemy 4 killed : 7
enemy 4 killed : 8
enemy 4 killed : 9
enemy 4 killed : 9
enemy 4 killed : 10
enemy 4 killed : 11
enemy 4 killed : 9
enemy 4 killed : 9 this part is the problem.
after i dig out the enemy script, i did change the code that kill and count the enemy, it did has 2 if statement i did reduce it one. and after i test it around 20 times or more, its seems work but im still not sure.. so
i know this is a hude code dump but pls can you guys can check it out if there is a locigal problem here ?
well im not a programmer and only working with gdscript around a year or so, so im not sure working of a lot of things, so i cant be sure, need an another view to tell if this okay...
var random_rotate
var state
var health = 9999
#var ID = "enemy4"
enum {
attack,
attack_2,
attack_3,
stop,
iddle,
angry
}
var first_attack = false
var second_attack = false
var third_attack = false
var player_first_attack_position:Vector3
var player_second_attack_position:Vector3
var player_third_attack_position:Vector3
var shield_got_hit = false
var collide = Vector3()
func _ready():
state = iddle
func _process(delta):
### kill count ###
if health == 0:
# if (ID == "enemy4"):
Global.total_enemy_slain += 1
Global.enemy_4_killed += 1
print ("enemy 4 killed : " + str(Global.enemy_4_killed))
queue_free()
global_transform.origin.y = 4
get_node("enemy4_crystals").rotate_y(0.01)
### hit the player
if $player_collision_raycast.is_colliding():
var get_collider = $player_collision_raycast.get_collider()
if get_collider.is_in_group("player"):
shield_got_hit = true
force_field_got_hit.play("force_field_got_hit_ani")
camera_shake_e4.play("camera_shake")
### take player position acording the timers time left function ###
if stepify($state_attack_timer.time_left,0.01) == 0.2:
player_first_attack_position = player.global_transform.origin
if stepify($state_attack_2_timer.time_left,0.01) == 0.2:
player_second_attack_position = player.global_transform.origin
if stepify($state_attack_3_timer.time_left,0.01) == 0.2:
player_third_attack_position = player.global_transform.origin
### enemy movment states ###
match state:
attack:
get_node("enemy4_crystals").rotation_degrees.y = 0
$Tween.interpolate_property(self,"translation",global_transform.origin,player_first_attack_position,0.05,Tween.EASE_IN,Tween.TRANS_LINEAR)
$Tween.start()
$enemy4_crystals/AnimationPlayer.play("enemy4_attack_ani")
$MotionTrail.trailEnabled = true
$MotionTrail2.trailEnabled = true
if shield_got_hit == true:
if shield_bar.shield_is_empty == false:
shield_bar.current_shield -= 50
shield_got_hit = false
if shield_bar.current_shield <= 0:
shield_bar.shield_is_empty = true
shield_bar.current_shield = 0
if shield_bar.shield_is_empty == true:
health_bar.current_health -= 50
attack_2:
get_node("enemy4_crystals").rotation_degrees.y = 0
$Tween.interpolate_property(self,"translation",global_transform.origin,player_second_attack_position,0.05,Tween.EASE_IN,Tween.TRANS_LINEAR)
$Tween.start()
$MotionTrail.trailEnabled = true
$MotionTrail2.trailEnabled = true
if shield_got_hit == true:
if shield_bar.shield_is_empty == false:
shield_bar.current_shield -= 50
shield_got_hit = false
if shield_bar.current_shield <= 0:
shield_bar.shield_is_empty = true
shield_bar.current_shield = 0
if shield_bar.shield_is_empty == true:
health_bar.current_health -= 50
attack_3:
get_node("enemy4_crystals").rotation_degrees.y = 0
$Tween.interpolate_property(self,"translation",global_transform.origin,player_third_attack_position,0.05,Tween.EASE_IN,Tween.TRANS_LINEAR)
$Tween.start()
$MotionTrail.trailEnabled = true
$MotionTrail2.trailEnabled = true
if shield_got_hit == true:
if shield_bar.shield_is_empty == false:
shield_bar.current_shield -= 50
shield_got_hit = false
if shield_bar.current_shield <= 0:
shield_bar.shield_is_empty = true
shield_bar.current_shield = 0
if shield_bar.shield_is_empty == true:
health_bar.current_health -= 50
stop:
translate(Vector3(0,0,0))
get_node("enemy4_crystals").rotation_degrees.y = 0
angry:
get_node("enemy4_crystals").rotate_y(0.1)
iddle:
$enemy4_crystals/AnimationPlayer.play("enemy4_iddle")
### attack movments ###
if first_attack == true:
state = attack
look_at(player_first_attack_position,Vector3.UP)
yield(get_tree().create_timer(0.1),"timeout")
state = stop
first_attack = false
$state_attack_2_timer.start()
if second_attack == true:
state = attack_2
look_at(player_second_attack_position,Vector3.UP)
yield(get_tree().create_timer(0.1),"timeout")
state = stop
second_attack = false
$state_attack_3_timer.start()
if third_attack == true:
state = attack_3
look_at(player_third_attack_position,Vector3.UP)
yield(get_tree().create_timer(0.1),"timeout")
state = stop
third_attack = false
yield(get_tree().create_timer(0.1),"timeout")
health = 0
### crystal drop ###
if health <= 0 :
var crystal_drop = preload ("res://sahneler/drop_coins/drop_coin_1.tscn").instance()
crystal_drop_add_child.add_child(crystal_drop)
crystal_drop.global_transform.origin = self.global_transform.origin
crystal_drop.random_drop_coin()
crystal_drop_sound_1.play()
# queue_free()
###crystal drop ###
### start of attack / first timer start ###
func _on_Area_body_entered(body):
if body.is_in_group("player"):
$state_attack_timer.start()
## timer 1 ##
func _on_state_attack_timer_timeout():
first_attack = true
##timer 2 ##
func _on_state_attack_2_timer_timeout():
second_attack = true
##timer 3 ##
func _on_state_attack_3_timer_timeout():
third_attack = true