TowerGame/scripts/bullet.gd

24 lines
554 B
GDScript3
Raw Normal View History

2025-04-26 16:02:13 +01:00
extends RigidBody3D
@export var damage_per_speed: float = 1.0
@export var min_damage: float = 10.0
@export var lifetime: float = 2.0
func _on_body_entered(body: Node) -> void:
2025-04-27 14:38:35 +01:00
#print("Bullet collided with %s" % body.name)
2025-04-26 16:02:13 +01:00
if body is Unit:
var speed: float = linear_velocity.length()
var damage: float = speed * damage_per_speed
if damage >= min_damage:
body.hurt(damage)
func _process(delta: float) -> void:
lifetime -= delta
if lifetime <= 0:
destroy()
if global_position.y < -10:
destroy()
func destroy() -> void:
queue_free()