class_name BallParticleEffects extends Node3D
## Controller for ball particle effects.

@export var splash_effect_scene: PackedScene

@onready var sand_particles: GPUParticles3D = %SandParticles

@onready var ball: GameBall = $".."


func play_splash() -> void:
	var effect: Node3D = splash_effect_scene.instantiate()
	ball.add_sibling(effect)
	effect.global_position = ball.global_position


func play_effect(terrain: Terrain.Type) -> void:
	global_rotation = Vector3.ZERO
	match terrain:
		Terrain.Type.SAND:
			# Adjust sand particle direction
			var material: ParticleProcessMaterial = sand_particles.process_material
			material.direction = -ball.linear_velocity.normalized()
			sand_particles.emitting = true
