diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2021-12-09 00:52:59 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2021-12-09 00:52:59 +0100 |
commit | 0f518727c28d3204415db14c7ca0e4f7cb653677 (patch) | |
tree | a595121771b69a52f17154d8e5c61b7e4b2b8190 /scripts/bullet.gd |
working
Diffstat (limited to 'scripts/bullet.gd')
-rw-r--r-- | scripts/bullet.gd | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/bullet.gd b/scripts/bullet.gd new file mode 100644 index 0000000..9b4434d --- /dev/null +++ b/scripts/bullet.gd @@ -0,0 +1,33 @@ +extends Spatial + +var _enemies_holder +var shooter + +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") + $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) + + hit_something = true + queue_free() |