extends GunkNode

@export var jitter_scale_factor := 0.02
@export var jitter_inflation_factor := 1.0

@export var splatter_scene: PackedScene

@onready var mesh_instance: MeshInstance3D = %MeshInstance3D


func _process(_delta: float) -> void:
	var shader: ShaderMaterial = mesh_instance.mesh.surface_get_material(0)
	var value := _sustained_damage / durability
	shader.set_shader_parameter("jitter_time_scale", value * jitter_scale_factor)
	shader.set_shader_parameter("vertex_inflation", value * jitter_inflation_factor)


func _destroy() -> void:
	var splatter: GPUParticles3D = splatter_scene.instantiate()
	add_sibling(splatter)
	splatter.global_position = global_position
	splatter.emitting = true
