From 8a11daf5448fdf09aa329d408056a0ccbb9f81d6 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sun, 22 Dec 2024 15:18:04 -0500 Subject: [PATCH] Forgot the floaty --- scenes/level_pool.tscn | 13 ++++++++----- scenes/win_box.gd | 34 ++++++++++++++++++++++++++++++++++ scripts/player.gd | 10 ++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 scenes/win_box.gd diff --git a/scenes/level_pool.tscn b/scenes/level_pool.tscn index 54d190d..836ea35 100644 --- a/scenes/level_pool.tscn +++ b/scenes/level_pool.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=21 format=4 uid="uid://bbqug1s083mdi"] +[gd_scene load_steps=22 format=4 uid="uid://bbqug1s083mdi"] [ext_resource type="PackedScene" uid="uid://ci2uamlnv8swy" path="res://assets/maps/levelpool.blend" id="1_cpckw"] [ext_resource type="PackedScene" uid="uid://cy86jyiy6skvk" path="res://scenes/player.tscn" id="2_eggmh"] @@ -7,6 +7,7 @@ [ext_resource type="AudioStream" uid="uid://cieprqff0h2nm" path="res://assets/sounds/door.wav" id="5_yad6d"] [ext_resource type="PackedScene" uid="uid://dnq81gfo5y4oy" path="res://components/group_trigger_component.tscn" id="6_f2del"] [ext_resource type="PackedScene" uid="uid://bfv04lp2tbxtd" path="res://scenes/monitor.tscn" id="6_qd2wd"] +[ext_resource type="Script" path="res://scenes/win_box.gd" id="7_oxf41"] [ext_resource type="AudioStream" uid="uid://d20ver6nfndbt" path="res://assets/sounds/dialog/start_dialog.wav" id="7_r1xli"] [ext_resource type="AudioStream" uid="uid://dbw14jkekqjrb" path="res://assets/sounds/dialog/win_dialog.wav" id="8_u6ajb"] @@ -159,7 +160,6 @@ libraries = { [node name="Monitor" parent="." instance=ExtResource("6_qd2wd")] transform = Transform3D(-0.877007, 0, -0.480477, 0, 1, 0, 0.480477, 0, -0.877007, -4.23016, 0.344398, -2.70049) -script = null [node name="HoleRim" type="StaticBody3D" parent="."] @@ -179,9 +179,12 @@ shape = SubResource("BoxShape3D_epqy0") transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 4.85, 0.25, -6.15) shape = SubResource("BoxShape3D_epqy0") -[node name="WinBox" parent="." instance=ExtResource("6_f2del")] +[node name="WinBox" type="Area3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, -1, -5) -group = "monitors" +script = ExtResource("7_oxf41") + +[node name="FloatPoint" type="Node3D" parent="WinBox"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) [node name="CollisionShape3D" type="CollisionShape3D" parent="WinBox"] shape = SubResource("BoxShape3D_dsbsn") @@ -203,7 +206,7 @@ stream = ExtResource("7_r1xli") [node name="WinDialog" type="AudioStreamPlayer3D" parent="Kreb"] stream = ExtResource("8_u6ajb") -[connection signal="activated_once" from="WinBox" to="Kreb/WinDialog" method="play" binds= [0.0]] +[connection signal="body_entered" from="WinBox" to="WinBox" method="_on_body_entered"] [connection signal="activated_once" from="DialogTrigger" to="Kreb/StartDialog" method="play" binds= [0]] [connection signal="finished" from="Kreb/WinDialog" to="ExitDoor" method="open"] diff --git a/scenes/win_box.gd b/scenes/win_box.gd new file mode 100644 index 0000000..b6e5cec --- /dev/null +++ b/scenes/win_box.gd @@ -0,0 +1,34 @@ +extends Area3D + + +@onready +var _dialog = $"../Kreb/WinDialog" +@onready +var _float_point = $FloatPoint + +var _lockout = false +var _grabbed_monitor: RigidBody3D + + +func _on_body_entered(body: Node3D) -> void: + if not body.is_in_group('monitors') or _lockout: + return + + _lockout = true + + _dialog.play() + + # TODO: Better way to get the player? + for player in get_tree().get_nodes_in_group("players"): + if player._held_object == body: + player.force_drop() + + _grabbed_monitor = body + _grabbed_monitor.remove_from_group('can_hold') + + +func _physics_process(delta: float) -> void: + if _grabbed_monitor: + var delta_position = _float_point.global_position - _grabbed_monitor.global_position + var move_speed = min(delta_position.length() * 400, 1000) + _grabbed_monitor.linear_velocity = delta_position.normalized() * move_speed * delta diff --git a/scripts/player.gd b/scripts/player.gd index 60161c9..c7fab16 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -108,6 +108,7 @@ func _physics_process(delta): if _held_object: _apply_holding_force(delta) + func _apply_friction(vel: Vector3, delta: float): var speed = sqrt(vel.x ** 2 + vel.z ** 2) if(speed == 0.0): return vel @@ -130,6 +131,7 @@ func _apply_friction(vel: Vector3, delta: float): return vel * newspeed + func _apply_accel(vel: Vector3, wishdir: Vector3, wishspeed: float, delta: float): var currentspeed = vel.dot(wishdir) var addspeed = wishspeed - currentspeed @@ -142,6 +144,7 @@ func _apply_accel(vel: Vector3, wishdir: Vector3, wishspeed: float, delta: float return vel + accelspeed * wishdir + func _apply_air_accel(vel: Vector3, wishvel: Vector3, wishspeed: float, delta: float): var wishveloc = wishvel.normalized() var wishspd = wishvel.length() @@ -160,12 +163,14 @@ func _apply_air_accel(vel: Vector3, wishvel: Vector3, wishspeed: float, delta: f return vel + accelspeed * wishveloc + func _apply_holding_force(delta): var hold_point = _camera.global_position - _camera.global_transform.basis.z * _held_object_distance var delta_position = hold_point - _held_object.global_position var move_speed = min(delta_position.length() * hold_force, max_hold_velocity) _held_object.linear_velocity = delta_position.normalized() * move_speed * delta + func _input(event): if event.is_action_pressed("pause"): _paused = not _paused @@ -216,3 +221,8 @@ func _input(event): if other.is_in_group('can_hold'): _held_object = other _held_object_distance = (Vector3(result.position) - _camera.global_position).length() + + +func force_drop(): + if _held_object: + _held_object = null