33 lines
709 B
GDScript
33 lines
709 B
GDScript
class_name Projectile
|
|
extends Area3D
|
|
|
|
@export var _collision_debug_material: Material
|
|
|
|
var _start_position: Vector3
|
|
var _velocity: Vector3
|
|
var _lifetime: float
|
|
|
|
var _life_timer: float
|
|
|
|
var _debug_collision_shapes := DebugCollisionShapes.new()
|
|
|
|
|
|
func _ready() -> void:
|
|
_life_timer = _lifetime
|
|
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
|
|
global_position = _start_position
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
if _life_timer <= 0:
|
|
queue_free()
|
|
|
|
_life_timer -= delta
|
|
global_position += _velocity * delta
|
|
|
|
|
|
func init(velocity: Vector3, start_position: Vector3, lifetime: float = 10) -> void:
|
|
_velocity = velocity
|
|
_start_position = start_position
|
|
_lifetime = lifetime
|