z-hack/src/Zombie.gd

32 lines
624 B
GDScript

extends KinematicBody2D
signal hit
onready var player
func set_player(p):
player = p
var velocity = Vector2()
var speed = 2000
func _process(delta):
if player.position.x > position.x:
velocity.x += speed
if player.position.x < position.x:
velocity.x -= speed
if player.position.y > position.y:
velocity.y += speed
if player.position.y < position.y:
velocity.y -= speed
func _physics_process(delta):
velocity = move_and_slide(velocity * delta)
func _on_Area2D_body_entered(body):
if body.is_in_group("player"):
print("player hit")
emit_signal("hit")
if body.is_in_group("weapons"):
queue_free()