Cloak.gd 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. extends MeshInstance
  2. class_name Cloak
  3. var mat
  4. var warp_power = 6
  5. var warp_color = Color8(50,100,200)
  6. var default_albedo
  7. var in_sound = preload("res://sounds/humming_in.ogg")
  8. var out_sound = preload("res://sounds/hmmming_out.ogg")
  9. func _ready():
  10. default_albedo = get_surface_material(0).albedo_color
  11. prepare_warp_material()
  12. func prepare_warp_material():
  13. mat = SpatialMaterial.new()
  14. mat.emission_enabled=true
  15. mat.emission = warp_color
  16. mat.emission_energy = 0
  17. mat.albedo_color = default_albedo
  18. mat.albedo_texture = load("res://neon_test_texture0.png")
  19. func warp(anitime, incoming = false):
  20. set_surface_material(0,mat)
  21. var tw1 = SDTween.new()
  22. if incoming:
  23. tw1.interpolate_property(mat,"emission_energy", warp_power, 0,anitime,Tween.TRANS_CUBIC,Tween.EASE_IN_OUT)
  24. make_warpsound(in_sound,3)
  25. else:
  26. tw1.interpolate_property(mat,"emission_energy", 0, warp_power,anitime,Tween.TRANS_CUBIC,Tween.EASE_IN_OUT)
  27. make_warpsound(out_sound,2)
  28. add_child(tw1)
  29. tw1.start()
  30. func make_warpsound(sound, volume = 2 ):
  31. var sp = SDStreamPlayer3D.new()
  32. sp.stream = sound
  33. sp.attenuation_model=AudioStreamPlayer3D.ATTENUATION_INVERSE_DISTANCE
  34. sp.unit_size = 0.1
  35. sp.unit_db = volume
  36. sp.play()
  37. add_child(sp)