Add enemies and let them be shot

This commit is contained in:
DerTyp7
2023-09-19 16:53:38 +02:00
parent f8b11b590b
commit 12cf356951
6 changed files with 84 additions and 32 deletions

22
Enemy.gd Normal file
View File

@@ -0,0 +1,22 @@
extends CharacterBody2D
var speed: float = 100.0
var motion: Vector2 = Vector2.ZERO
func _ready():
pass
func _physics_process(delta):
var player = get_parent().get_node("Player")
var direction = (player.position - position).normalized()
motion = direction * speed
look_at(player.position)
move_and_collide(motion * delta)
func _on_area_2d_body_entered(body):
print("Bullet hit")
print(body.name)
if "Bullet" in body.name:
queue_free()