Projectile.gd 626 B

123456789101112131415161718192021222324
  1. extends Node2D
  2. class_name Projectile
  3. #
  4. var origin : Vector2 = Vector2.ZERO
  5. var destination : Vector2 = Vector2.ZERO
  6. var delay : float = 0.0
  7. var elapsed : float = 0.0
  8. var fade : float = 0.15
  9. @onready var light = $LightSource
  10. #
  11. func _physics_process(delta):
  12. elapsed = min(delay, elapsed + delta)
  13. if elapsed == delay:
  14. Util.RemoveNode(self, get_parent())
  15. else:
  16. var scaleRatio : float = Util.FadeInOutRatio(elapsed, delay, fade, fade)
  17. if light:
  18. light.rescale = scaleRatio
  19. scale = lerp(Vector2.ZERO, Vector2.ONE, scaleRatio)
  20. global_position = lerp(origin, destination, elapsed / delay)