giants-godot/entities/weapon.gd
2021-09-08 18:36:41 +02:00

45 lines
1.4 KiB
GDScript

extends Spatial
class_name Weapon
var projectile: PackedScene
var holder: Spatial
var activate_efx = null
var held_hand = "right"
var activate_sound = preload("res://assets/audio/Sounds/SR_SBWPL.xx_reaperlev1.gzp.wav")
var current_activate_animation_value: Vector2 = Vector2.ZERO
var wanted_activate_animation_value: float = 0
func setup(_holder: Spatial):
holder = _holder
func activate(_to: Vector3):
activate_efx = preload("res://effects/anim_bow_charging.tscn").instance()
activate_efx.get_node("AudioStreamPlayer3D").stream = activate_sound
add_child(activate_efx)
activate_efx.global_transform.origin = global_transform.origin
wanted_activate_animation_value = 1
func deactivate(to: Vector3):
wanted_activate_animation_value = 0
fire(to)
func _process(delta):
if is_visible_in_tree():
current_activate_animation_value = current_activate_animation_value.linear_interpolate(Vector2(wanted_activate_animation_value, 0), delta * 10)
holder.get_node("Reaper2/AnimationTree").set("parameters/blend_draw/blend_amount", current_activate_animation_value.x)
func fire(to: Vector3):
# deactivate
if activate_efx:
activate_efx.queue_free()
# create projectile
if projectile:
var proj = projectile.instance()
get_tree().root.add_child(proj)
var transform = holder.transform
transform.origin = global_transform.origin
proj.create(transform, to, [holder])