41 lines
1.1 KiB
GDScript
41 lines
1.1 KiB
GDScript
extends Projectile
|
|
|
|
@export var max_bounces : int = 10
|
|
@export var collision_shape: CollisionShape3D
|
|
@export var mesh: MeshInstance3D
|
|
|
|
@onready var material = mesh.get_surface_override_material(0)
|
|
|
|
var bounces = 0
|
|
var start_time
|
|
var end_time
|
|
var despawning = false
|
|
|
|
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)
|
|
|
|
if despawning:
|
|
linear_velocity.y -= .1 * delta
|
|
|
|
func despawn():
|
|
collision_shape.disabled = true
|
|
gravity_scale = 0
|
|
despawning = true
|
|
await get_tree().create_timer(2).timeout
|
|
queue_free()
|
|
|
|
|
|
func _on_timer_timeout() -> void:
|
|
despawn()
|