Guest User

slash.gd

a guest
May 10th, 2026
68
0
198 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. extends Area2D
  2.  
  3. @export var speed = 700.0
  4. @export var damage = 20
  5. @export var lifetime = 0.1
  6. @export var knockback_strength = 200.0
  7.  
  8. var direction = Vector2.RIGHT
  9. var source = null
  10. var already_hit = false
  11.  
  12.  
  13. func _ready():
  14. print("[PROJECTILE] SPAWNED")
  15. print("[PROJECTILE] direction:", direction)
  16.  
  17. $Timer.wait_time = lifetime
  18. $Timer.start()
  19.  
  20. # safety: ensure signal is connected
  21. if not body_entered.is_connected(_on_body_entered):
  22. body_entered.connect(_on_body_entered)
  23.  
  24.  
  25. func _process(delta):
  26. position += direction * speed * delta
  27.  
  28.  
  29. func _on_body_entered(body):
  30. if already_hit:
  31. return
  32.  
  33. if body == source:
  34. return
  35.  
  36. print("[PROJECTILE] HIT:", body.name)
  37.  
  38. var combat = body.get_node_or_null("CombatComponent")
  39.  
  40. if combat != null:
  41. already_hit = true
  42.  
  43. var knock_dir = direction
  44. var diff = body.global_position - global_position
  45.  
  46. if diff.length() > 0.001:
  47. knock_dir = diff.normalized()
  48.  
  49. combat.take_damage(damage, knock_dir, knockback_strength)
  50.  
  51. queue_free()
  52.  
  53.  
  54. func _on_timer_timeout():
  55. queue_free()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment