Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Area2D
- @export var speed = 700.0
- @export var damage = 20
- @export var lifetime = 0.1
- @export var knockback_strength = 200.0
- var direction = Vector2.RIGHT
- var source = null
- var already_hit = false
- func _ready():
- print("[PROJECTILE] SPAWNED")
- print("[PROJECTILE] direction:", direction)
- $Timer.wait_time = lifetime
- $Timer.start()
- # safety: ensure signal is connected
- if not body_entered.is_connected(_on_body_entered):
- body_entered.connect(_on_body_entered)
- func _process(delta):
- position += direction * speed * delta
- func _on_body_entered(body):
- if already_hit:
- return
- if body == source:
- return
- print("[PROJECTILE] HIT:", body.name)
- var combat = body.get_node_or_null("CombatComponent")
- if combat != null:
- already_hit = true
- var knock_dir = direction
- var diff = body.global_position - global_position
- if diff.length() > 0.001:
- knock_dir = diff.normalized()
- combat.take_damage(damage, knock_dir, knockback_strength)
- queue_free()
- func _on_timer_timeout():
- queue_free()
Advertisement
Add Comment
Please, Sign In to add comment