Projectile.gd 836 B

123456789101112131415161718192021222324252627282930313233
  1. extends Node2D
  2. class_name Projectile
  3. #
  4. @export var canRotate : bool = false
  5. var origin : Vector2 = Vector2.ZERO
  6. var destination : Vector2 = Vector2.ZERO
  7. var delay : float = 0.0
  8. var elapsed : float = 0.0
  9. var fade : float = 0.15
  10. var light : LightSource = null
  11. #
  12. func _physics_process(delta):
  13. elapsed = min(delay, elapsed + delta)
  14. if elapsed == delay:
  15. Util.RemoveNode(self, get_parent())
  16. else:
  17. var scaleRatio : float = Util.FadeInOutRatio(elapsed, delay, fade, fade)
  18. if light:
  19. light.rescale = scaleRatio
  20. scale = lerp(Vector2.ZERO, Vector2.ONE, scaleRatio)
  21. global_position = lerp(origin, destination, elapsed / delay)
  22. func _ready():
  23. if has_node("LightSource"):
  24. light = get_node("LightSource")
  25. if canRotate:
  26. rotation = origin.angle_to_point(destination)
  27. set("set_speed_scale", delay)