class_name Liquid extends Area3D const VERY_FAST_TRANSITION: float = 0.03125 const DROPLET_WAVELENGTH: float = 2.0 const DROPLET_AMPLITUDE: float = 0.125 @export var descriptor: LiquidDescriptor = ( preload("res://zones/Liquid/descriptors/Water.tres") ) @export var frequency: float = 1.0 @export var wavelength: float = 1.0 @export var amplitude: float = 1.0 @onready var audio_player := $'AudioStreamPlayer3D' as AudioStreamPlayer3D @onready var particles := $'GPUParticles3D' as GPUParticles3D @onready var mesh := $'..' as MeshInstance3D func _ready() -> void: body_entered.connect(splash) body_exited.connect(splash) FX.get_camera().area_entered.connect(_on_camera_entered) FX.get_camera().area_exited.connect(_on_camera_exited) mesh.set_surface_override_material( 0, preload("res://zones/Liquid/LiquidMaterial.tres") ) mesh.set_instance_shader_parameter(&'color', descriptor.color) mesh.set_instance_shader_parameter(&'frequency', frequency) mesh.set_instance_shader_parameter(&'wavelength', wavelength) mesh.set_instance_shader_parameter(&'amplitude', amplitude) particles.set_instance_shader_parameter(&'color', descriptor.color) particles.set_instance_shader_parameter(&'frequency', frequency) particles.set_instance_shader_parameter(&'wavelength', DROPLET_WAVELENGTH) particles.set_instance_shader_parameter(&'amplitude', DROPLET_AMPLITUDE) gravity = descriptor.buoyancy gravity_direction = Vector3.UP gravity_space_override = Area3D.SPACE_OVERRIDE_COMBINE linear_damp = descriptor.viscosity linear_damp_space_override = Area3D.SPACE_OVERRIDE_COMBINE func splash(body: PhysicsBody3D) -> void: if body is RigidBody3D: audio_player.global_position = body.global_position particles.global_position = body.global_position audio_player.play() particles.restart() particles.emitting = true func _on_camera_entered(where: Area3D) -> void: if where == self: var level := Storyboard.get_current_level() as LevelDescriptor if level: var vfx := level.fx as ScreenEffectsConfiguration if vfx and vfx.set_tint: FX.tint(vfx.tint*descriptor.color, 0.0) else: FX.tint(descriptor.color, 0.0) else: FX.tint(descriptor.color, 0.0) FX.hide_weather_particles() func _on_camera_exited(where: Area3D) -> void: if where == self: var level := Storyboard.get_current_level() as LevelDescriptor if level: var vfx := level.fx as ScreenEffectsConfiguration if vfx and vfx.set_tint: FX.tint(vfx.tint, VERY_FAST_TRANSITION) else: FX.tint(Color.WHITE, VERY_FAST_TRANSITION) else: FX.tint(Color.WHITE, VERY_FAST_TRANSITION) FX.unhide_weather_particles()