I want to add an enemy that shoots at the player. The problem is that it shoots at this specific block that breaks when the player touches him.
here is the snake code
extends KinematicBody2D
onready var BULLET_SCENE = preload("res://bullet.tscn")
var player = null
func fire():
var bullet = BULLET_SCENE.instance()
bullet.position = get_global_position()
bullet.player = player
get_parent().add_child(bullet)
$Timer.set_wait_time(1)
func _on_Area2D_body_entered(body):
if body != self:
player = body
func _on_Area2D_body_exited(body):
player = null
func _on_Timer_timeout():
if player != null:
fire()
here the block
extends Area2D
func _physics_process(_delta):
var bodies = get_overlapping_bodies()
for body in bodies:
if is_instance_valid(body):
if body.name == "Player":
$AnimationPlayer.play("destroyed")
yield($AnimationPlayer, "animation_finished")
queue_free()
P.S. I don't think it is the layer and mask. For the snake, it only recognises the player and for the block, it only recognises the player.