diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-19 17:34:04 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-19 17:34:04 +0100 |
commit | 18188524536644ba558f65fc3e866739bd7d0aa5 (patch) | |
tree | e2eb05b13e67baf24613d7d7c97667c9abaea649 /scripts | |
parent | 1873ccff40f81c4d20fb752df1fe34adf33fd254 (diff) |
doc turrets
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/bullet.gd | 17 | ||||
-rw-r--r-- | scripts/turret.gd | 14 |
2 files changed, 25 insertions, 6 deletions
diff --git a/scripts/bullet.gd b/scripts/bullet.gd index dd9793e..3a50a12 100644 --- a/scripts/bullet.gd +++ b/scripts/bullet.gd @@ -3,7 +3,7 @@ extends Spatial var _enemies_holder var shooter -var damage = 1 +var damage = 0 var timer = 0 var time_life = 3 @@ -12,11 +12,21 @@ var hit_something = false var bounce = false var hitlist = [] +var ignore_collisions = false + func _ready(): + if ignore_collisions: return _enemies_holder = get_tree().root.get_node("world").find_node("enemies") var _err = $Area.connect("body_entered", self, "collided") func _physics_process(delta): + timer += delta + if timer >= time_life: + queue_free() + return + + if ignore_collisions: return + var forward_dir = -global_transform.basis.z.normalized() if bounce: var space: PhysicsDirectSpaceState = get_world().direct_space_state @@ -42,12 +52,9 @@ func _physics_process(delta): else: global_translate(forward_dir * speed * delta) - - timer += delta - if timer >= time_life: - queue_free() func collided(body): + if ignore_collisions: return var parent = body.get_parent() if parent == shooter: return if parent in hitlist: return diff --git a/scripts/turret.gd b/scripts/turret.gd index 6fbddeb..a9dfb74 100644 --- a/scripts/turret.gd +++ b/scripts/turret.gd @@ -15,6 +15,7 @@ var aim_mode = "first" var _target = null var projectile : PackedScene +var ray : PackedScene var info : Dictionary @@ -28,6 +29,7 @@ func _ready(): _enemies_holder = root.find_node("enemies") projectile = load("res://scenes/projectiles/bullet.tscn") + ray = load("res://scenes/projectiles/ray.tscn") func refresh_normal (): _normal = transform.basis * Vector3.UP @@ -165,7 +167,7 @@ func shoot_bullet (dir : Basis, bounce = false): func shoot_ray (dir : Basis): var space: PhysicsDirectSpaceState = get_world().direct_space_state var from = _shooting_point - var to = _shooting_point - dir.z*info.range; + var to = _shooting_point - dir.z*info.range var mask = 0b1101 var result = space.intersect_ray(from, to, _path.nodes, mask) @@ -174,3 +176,13 @@ func shoot_ray (dir : Basis): var groups = parent.get_groups() if "enemies" in groups: _enemies_holder.damage(parent.name, info.damage) + + var distance = result.position.distance_to(from) + + var instance = ray.instance() + instance.ignore_collisions = true + _projectiles_holder.add_child(instance) + instance.transform.origin = _shooting_point - dir.z*0.3; + instance.transform.basis = dir + instance.transform.basis.z *= distance + instance.time_life = 0.05 |