How to make the enemy stop shooting after the death of a player?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zidd

Enemy Shooting Code

if $RayCast2D2.is_colliding():

		var coll = $RayCast2D2.get_collider()

		if coll.name == "Player":

			if is_dead == false:
				
				velocity.x = 0
				
				var bul = bullet.instance(1)
				
				if sign($Position2D.position.x) == 1:
					bul.set_bullet_direction(1)
					
					bul.position = $Position2D.global_position
					
				else:
					bul.set_bullet_direction(-1)
					
					bul.position = ($Position2D.global_position) + Vector2(-35, 0)
					
				if ttim > 1:
					get_node("../").add_child(bul)
					$AnimatedSprite.play("shoot")
					ttim = 0

Is the variable is_dead actually assigned “true” when the player does die?

Ertain | 2020-04-10 19:22

yes, is_dead actually assigned “true” when the player does die

Zidd | 2020-04-14 17:59

Can’t really help you. :-/ All I can do is a bit of code clean up. Hope this helps.

if $RayCast2D2.is_colliding():
        var coll = $RayCast2D2.get_collider()
        if coll.name == "Player":
            if not is_dead:
                velocity.x = 0
                var bul = bullet.instance(1)
                if sin($Position2D.position.x) == 1:
                    bul.set_bullet_direction(1)
                    bul.position = $Position2D.global_position
                else:
                    bul.set_bullet_direction(-1)
                    bul.position = $Position2D.global_position + Vector2(-35, 0)
                if ttim > 1:
                    get_node("../").add_child(bul)
                    $AnimatedSprite.play("shoot")
                    ttim = 0
            else:
                $AnimatedSprite.stop()

Ertain | 2020-04-14 20:12