extends Projectile @export var max_bounces : int = 10 @onready var collision_shape: CollisionShape3D = $CollisionShape3D @onready var mesh: MeshInstance3D = $MeshInstance3D @onready var material = mesh.get_surface_override_material(0) var bounces = 0 var start_time var end_time const EMISSION_MAX : float = 200 const EMISSION_LIFETIME : float = 1.75 #in seconds const VELOCITY_REQUIRED_TO_HIT : float = 10 # Called when the node enters the scene tree for the first time. func _ready() -> void: start_time = Time.get_ticks_msec() end_time = start_time + (EMISSION_LIFETIME * 1000) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: var current_time = (Time.get_ticks_msec())/end_time material.emission_energy_multiplier = clamp(lerp(EMISSION_MAX,0.0,current_time),0,EMISSION_MAX) func _on_body_entered(body: Node) -> void: bounces += 1 if bounces >= max_bounces: despawn() if linear_velocity.length() >= VELOCITY_REQUIRED_TO_HIT: damage(body) func despawn(): collision_shape.disabled = true await get_tree().create_timer(1).timeout self.queue_free() func _on_timer_timeout() -> void: despawn()