summaryrefslogtreecommitdiff
path: root/scenes/defenders/warlock_projectile.gd
blob: 0a1cff4033a443e915133330bcf999fdd684cbe8 (plain)
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
extends CharacterBody2D

var target
var speed = 100
var path_name = ""
var projectile_damage

func _physics_process(_delta: float):
	var path_spawner_node = get_tree().get_root().get_node("Main/PathSpawner")
	for i in path_spawner_node.get_child_count():
		if path_spawner_node.get_child(i).name == path_name:
			target = path_spawner_node.get_child(i).get_child(0).get_child(0)

	# another tower destroyed this target
	if !is_instance_valid(target):
		queue_free()
	else:
		target = target.global_position
		velocity = global_position.direction_to(target) * speed
		look_at(target)
		move_and_slide()


func _on_area_2d_body_entered(body: Node2D):
	if "CrawlerSoldier" in body.name:
		body.health -= projectile_damage
		queue_free()