24 lines
553 B
GDScript3
24 lines
553 B
GDScript3
|
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:
|
||
|
print("Bullet collided with %s" % body.name)
|
||
|
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()
|