diff --git a/player/Player.tscn b/player/Player.tscn index f32a99a..5f71dbb 100644 --- a/player/Player.tscn +++ b/player/Player.tscn @@ -1,12 +1,11 @@ -[gd_scene load_steps=17 format=3 uid="uid://b5i1sqd88wlle"] +[gd_scene load_steps=16 format=3 uid="uid://b5i1sqd88wlle"] [ext_resource type="Script" path="res://player/Player.gd" id="1_rujcr"] [ext_resource type="Script" path="res://player/Head.gd" id="2_ohlgu"] [ext_resource type="Script" path="res://player/OnHand.gd" id="3_3rcjl"] [ext_resource type="Theme" uid="uid://c5a1nyqumj46j" path="res://menu/menu_theme.tres" id="4_d7ru6"] [ext_resource type="Shader" path="res://player/crosshair.gdshader" id="4_dut1p"] -[ext_resource type="Script" path="res://player/SplashController.gd" id="5_wnbq8"] -[ext_resource type="AudioStream" uid="uid://xretxahxbqdr" path="res://assets/splash.ogg" id="6_xi537"] +[ext_resource type="PackedScene" uid="uid://dc147tdie7oem" path="res://player/SplashController.tscn" id="6_hf66s"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_aqp8x"] metallic_specular = 0.0 @@ -262,8 +261,5 @@ metadata/_edit_lock_ = true [node name="RigidDynamicBody3D" type="RigidBody3D" parent="."] -[node name="SplashController" type="Node" parent="."] -script = ExtResource("5_wnbq8") - -[node name="SplashSound" type="AudioStreamPlayer" parent="SplashController"] -stream = ExtResource("6_xi537") +[node name="SplashController" parent="." instance=ExtResource("6_hf66s")] +target_path = NodePath("..") diff --git a/player/SplashController.gd b/player/SplashController.gd index ce91f96..42ad4f4 100644 --- a/player/SplashController.gd +++ b/player/SplashController.gd @@ -1,13 +1,24 @@ extends Node -@onready var player: Node3D = $".." -@onready var spawn_point: Vector3 = player.position +@export_node_path(CharacterBody3D) var target_path: NodePath +@export var splash_threshold: float = 0.0 + +@onready var target: CharacterBody3D = get_node(target_path) +@onready var spawn_point: Vector3 = target.position @onready var splash_sound: AudioStreamPlayer = $SplashSound +signal splashed() + + +func splash(): + splash_sound.play() + target.position = spawn_point + target.velocity = Vector3.ZERO + emit_signal("splashed") + + func _process(_delta): - if player.position.y < 0: - splash_sound.play() - player.position = spawn_point - player.velocity = Vector3.ZERO + if target.position.y < splash_threshold: + splash() diff --git a/player/SplashController.tscn b/player/SplashController.tscn new file mode 100644 index 0000000..fcb28c1 --- /dev/null +++ b/player/SplashController.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=3 uid="uid://dc147tdie7oem"] + +[ext_resource type="Script" path="res://player/SplashController.gd" id="1_m4yh2"] +[ext_resource type="AudioStream" uid="uid://xretxahxbqdr" path="res://assets/splash.ogg" id="2_esng3"] + +[node name="SplashController" type="Node"] +script = ExtResource("1_m4yh2") + +[node name="SplashSound" type="AudioStreamPlayer" parent="."] +stream = ExtResource("2_esng3")