forked from Miziziziz/TopDownShooter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zombie.gd
30 lines (21 loc) · 594 Bytes
/
Zombie.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
extends CharacterBody2D
const MOVE_SPEED = 200
@onready var raycast = $RayCast2D
var player = null
func _ready():
add_to_group("zombies")
func _physics_process(delta):
if player == null:
return
var vec_to_player = player.global_position - global_position
vec_to_player = vec_to_player.normalized()
global_rotation = atan2(vec_to_player.y, vec_to_player.x)
move_and_collide(vec_to_player * MOVE_SPEED * delta)
if raycast.is_colliding():
var coll = raycast.get_collider()
if coll.name == "Player":
coll.kill()
func kill():
queue_free()
func set_player(p):
player = p