aboutsummaryrefslogtreecommitdiff
path: root/scripts/bullet.gd
blob: 994d3d19b4114944c379d66b334be152dc1b838d (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
28
29
30
31
32
33
34
35
extends Spatial

var _enemies_holder
var shooter

var damage = 1

var timer = 0
var time_life = 3
var speed = 7
var hit_something = false

func _ready():
	_enemies_holder = get_tree().root.get_child(0).find_node("enemies")
	var _err = $Area.connect("body_entered", self, "collided")

func _physics_process(delta):
	var forward_dir = -global_transform.basis.z.normalized()
	global_translate(forward_dir * speed * delta)

	timer += delta
	if timer >= time_life:
		queue_free()

func collided(body):
	var parent = body.get_parent()
	if parent == shooter: return
	
	if hit_something == false:
		var groups = parent.get_groups()
		if "enemies" in groups:
			_enemies_holder.damage(parent.name, damage)

	hit_something = true
	queue_free()