extends CPUParticles3D
## One-shot blood spray. Add as a child of whatever bleeds, then call burst().

func _ready() -> void:
	var mat := StandardMaterial3D.new()
	mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
	mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
	mat.vertex_color_use_as_albedo = true
	mat.cull_mode = BaseMaterial3D.CULL_DISABLED

	var sphere := SphereMesh.new()
	sphere.radius = 0.07
	sphere.height = 0.14
	sphere.radial_segments = 4
	sphere.rings = 2
	sphere.material = mat

	var ramp := Gradient.new()
	ramp.set_color(0, Color(1.0, 0.02, 0.02, 1.0))
	ramp.set_color(1, Color(0.25, 0.0, 0.0, 0.0))

	var scale_curve := Curve.new()
	scale_curve.add_point(Vector2(0.0, 1.0))
	scale_curve.add_point(Vector2(0.6, 0.5))
	scale_curve.add_point(Vector2(1.0, 0.0))

	mesh               = sphere
	color_ramp         = ramp
	scale_amount_curve = scale_curve
	one_shot           = true
	explosiveness      = 0.9
	amount             = 25
	lifetime           = 1.1
	randomness         = 0.4
	local_coords       = false
	spread             = 80.0
	gravity            = Vector3(0.0, -7.0, 0.0)
	initial_velocity_min = 4.0
	initial_velocity_max = 11.0
	scale_amount_min   = 0.5
	scale_amount_max   = 1.6
	emitting           = false


# Fire a burst at a world position, sprayed along dir (biased upward).
func burst(at: Vector3, dir: Vector3) -> void:
	global_position = at
	direction = (dir * 0.6 + Vector3.UP * 0.4).normalized()
	restart()
