diff --git a/godot/scenes/node_3d.tscn b/godot/scenes/node_3d.tscn index 82d1eea..722ab31 100644 --- a/godot/scenes/node_3d.tscn +++ b/godot/scenes/node_3d.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=9 format=3 uid="uid://c634jlnd870wg"] +[gd_scene load_steps=13 format=3 uid="uid://c634jlnd870wg"] [ext_resource type="Script" path="res://src/camera_trigger.ts" id="2_anf5t"] [ext_resource type="PackedScene" uid="uid://b46lmxhgyg5fh" path="res://scenes/player.tscn" id="2_pd54o"] +[ext_resource type="Script" path="res://src/interactable.ts" id="2_v376t"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ijx74"] albedo_color = Color(0.427493, 0.427493, 0.427493, 1) @@ -16,6 +17,14 @@ albedo_color = Color(0.427493, 0.427493, 0.427493, 1) [sub_resource type="BoxShape3D" id="BoxShape3D_fx65l"] +[sub_resource type="SphereShape3D" id="SphereShape3D_e4gtv"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_3x5dl"] +albedo_color = Color(0, 0.65008, 0.0485462, 1) +metallic = 0.5 + +[sub_resource type="SphereMesh" id="SphereMesh_frheh"] + [node name="Node3D" type="Node3D"] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] @@ -126,6 +135,20 @@ camera = NodePath("../Camera3D3") transform = Transform3D(1.4, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0) shape = SubResource("BoxShape3D_fx65l") +[node name="Props" type="Node" parent="."] + +[node name="Area3D" type="Area3D" parent="Props"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 3, -12.5) +script = ExtResource("2_v376t") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Props/Area3D"] +transform = Transform3D(2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0) +shape = SubResource("SphereShape3D_e4gtv") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Props/Area3D"] +material_override = SubResource("StandardMaterial3D_3x5dl") +mesh = SubResource("SphereMesh_frheh") + [node name="CharacterBody3D" parent="." instance=ExtResource("2_pd54o")] [connection signal="body_entered" from="Cameras/Camera Trigger" to="Cameras/Camera Trigger" method="_on_body_entered"] diff --git a/godot/scenes/player.tscn b/godot/scenes/player.tscn index 46e05d7..0fef230 100644 --- a/godot/scenes/player.tscn +++ b/godot/scenes/player.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=19 format=3 uid="uid://b46lmxhgyg5fh"] +[gd_scene load_steps=21 format=3 uid="uid://b46lmxhgyg5fh"] [ext_resource type="Script" path="res://src/player.ts" id="1_a88ao"] [ext_resource type="Script" path="res://src/player_animation.ts" id="2_ypldj"] [ext_resource type="Script" path="res://src/player_input.ts" id="3_b7c8b"] [ext_resource type="PackedScene" uid="uid://dv1aoe06v6dbo" path="res://scenes/player_mesh.tscn" id="4_27blp"] +[ext_resource type="Script" path="res://src/interactor.ts" id="5_nujwx"] [sub_resource type="CylinderShape3D" id="CylinderShape3D_x8bhs"] @@ -66,6 +67,8 @@ states/Walking/position = Vector2(579, 98) transitions = ["Start", "Idle", SubResource("AnimationNodeStateMachineTransition_a51th"), "Idle", "Interact", SubResource("AnimationNodeStateMachineTransition_lhuck"), "Interact", "Idle", SubResource("AnimationNodeStateMachineTransition_jf23w"), "Idle", "Walking", SubResource("AnimationNodeStateMachineTransition_dxcas"), "Walking", "Interact", SubResource("AnimationNodeStateMachineTransition_5x23f"), "Walking", "Idle", SubResource("AnimationNodeStateMachineTransition_mq4ne"), "Walking", "SlowRun", SubResource("AnimationNodeStateMachineTransition_rx5qf"), "SlowRun", "Walking", SubResource("AnimationNodeStateMachineTransition_yo8po")] graph_offset = Vector2(264, 15) +[sub_resource type="SphereShape3D" id="SphereShape3D_cvkom"] + [node name="CharacterBody3D" type="CharacterBody3D"] script = ExtResource("1_a88ao") player_input = NodePath("Input") @@ -90,133 +93,143 @@ script = ExtResource("3_b7c8b") [node name="PlayerMesh" parent="." instance=ExtResource("4_27blp")] [node name="Skeleton3D" parent="PlayerMesh/Armature" index="0"] -bones/0/position = Vector3(10.8323, 100.566, 1.76934) -bones/0/rotation = Quaternion(-0.0230531, -0.134826, 0.0330271, 0.99005) +bones/0/position = Vector3(-0.0791573, 100.981, 0.65403) +bones/0/rotation = Quaternion(-0.0163855, -0.0229987, -0.0883498, 0.995689) bones/1/position = Vector3(-1.08778e-06, 8.00974e-08, -5.45755e-07) -bones/2/rotation = Quaternion(-0.126312, 0.00390559, -0.0612111, 0.990093) +bones/2/rotation = Quaternion(-0.0870186, -0.0161811, 0.0903036, 0.991973) bones/3/position = Vector3(1.2666e-07, 1.38208e-06, 4.63426e-06) -bones/4/rotation = Quaternion(0.0179489, -0.00825122, -0.0178849, 0.999645) +bones/4/rotation = Quaternion(-0.0254263, -0.0151828, 0.0203413, 0.999354) bones/5/position = Vector3(-8.19564e-07, -1.46851e-05, 4.30644e-06) -bones/6/rotation = Quaternion(0.0308461, -0.00732419, -0.0178495, 0.999338) +bones/6/rotation = Quaternion(-0.0125175, -0.0151411, 0.0203446, 0.9996) bones/7/position = Vector3(3.57632e-07, -2.42144e-05, -3.53158e-06) -bones/8/rotation = Quaternion(-0.556759, 0.512207, -0.549306, -0.354861) +bones/8/rotation = Quaternion(-0.52679, 0.535354, -0.560367, -0.349108) bones/9/position = Vector3(1.93715e-07, -8.76188e-06, -1.82156e-05) bones/10/position = Vector3(-2.22259e-06, 10.8382, 6.657e-05) -bones/10/rotation = Quaternion(0.535951, -0.123005, -0.0947963, 0.829844) +bones/10/rotation = Quaternion(0.508487, -0.157066, -0.0281914, 0.846154) bones/11/position = Vector3(1.66958e-06, -2.30764e-05, 5.90135e-07) -bones/12/rotation = Quaternion(6.63038e-08, 4.62427e-08, -0.238361, 0.971177) +bones/12/rotation = Quaternion(-1.37529e-07, -3.07905e-08, -0.237243, 0.97145) bones/13/position = Vector3(7.10815e-06, 2.49848e-06, -3.67706e-07) bones/14/position = Vector3(1.00884e-05, 28.3289, 1.42043e-06) -bones/14/rotation = Quaternion(-0.00100366, -0.153901, -0.0163265, 0.987951) +bones/14/rotation = Quaternion(-0.00736037, -0.143173, -0.0118039, 0.9896) bones/15/position = Vector3(1.43223e-06, -9.47448e-06, -3.04991e-06) -bones/16/rotation = Quaternion(0.130922, -0.000536525, 0.0200024, 0.991191) +bones/16/rotation = Quaternion(0.179817, 0.000758776, 0.0177523, 0.98354) bones/17/position = Vector3(2.78027e-07, -1.63051e-05, 2.7709e-07) bones/18/position = Vector3(-7.17311e-07, 3.6, -4.46059e-05) -bones/18/rotation = Quaternion(0.125981, 7.59033e-08, 0.0153541, 0.991914) +bones/18/rotation = Quaternion(0.174418, 8.39337e-08, 0.0212574, 0.984442) bones/19/position = Vector3(-1.09796e-06, -1.6639e-05, -1.30592e-05) -bones/20/rotation = Quaternion(0.19325, 7.59658e-09, 0.0235519, 0.980867) +bones/20/rotation = Quaternion(0.239288, -2.60638e-08, 0.0291628, 0.970511) bones/21/position = Vector3(-3.42208e-06, -3.57069e-06, -7.88492e-06) bones/22/position = Vector3(-2.66578e-06, 2.11579, -6.80612e-06) bones/23/position = Vector3(1.99676e-06, 2.3176e-06, 1.13522e-06) bones/24/position = Vector3(-2.81929e-05, 9.5325, 4.46934e-05) -bones/24/rotation = Quaternion(0.118124, 0.00017292, 0.0129408, 0.992915) +bones/24/rotation = Quaternion(0.159386, 0.00274518, 0.00219892, 0.98721) bones/25/position = Vector3(-2.64221e-06, 1.33002e-05, 9.27813e-06) bones/26/position = Vector3(-3.12982e-06, 3.70001, -1.88553e-05) -bones/26/rotation = Quaternion(0.118005, -1.8283e-08, 0.0143819, 0.992909) +bones/26/rotation = Quaternion(0.182238, 8.9875e-08, 0.0222102, 0.983004) bones/27/position = Vector3(4.8121e-06, -1.06792e-05, -1.50226e-05) bones/28/position = Vector3(3.86115e-06, 2.95001, -1.38305e-05) -bones/28/rotation = Quaternion(0.221719, 0.0356031, 0.035285, 0.973821) +bones/28/rotation = Quaternion(0.304902, 0.0162707, 0.0424629, 0.951298) bones/31/position = Vector3(1.86637e-06, 5.9802e-06, -1.467e-05) -bones/32/rotation = Quaternion(0.173185, -0.000326617, 0.0229624, 0.984622) +bones/32/rotation = Quaternion(0.224394, 0.0023834, 0.0169417, 0.974348) bones/33/position = Vector3(-2.25109e-06, -9.16777e-06, 1.35742e-05) bones/34/position = Vector3(-1.61634e-06, 3.37927, -2.16157e-06) -bones/34/rotation = Quaternion(0.0978745, -6.00722e-08, 0.0119283, 0.995127) +bones/34/rotation = Quaternion(0.139901, 4.28371e-08, 0.0170503, 0.990019) bones/36/position = Vector3(-1.34902e-06, 2.88968, 1.45266e-05) -bones/36/rotation = Quaternion(0.1665, 0.102706, 0.0382309, 0.979933) +bones/36/rotation = Quaternion(0.210679, 0.100051, 0.0479816, 0.971237) bones/37/position = Vector3(7.45909e-07, -8.48482e-06, 1.51202e-05) bones/38/position = Vector3(-7.0702e-07, 2.63882, -1.46823e-05) bones/39/position = Vector3(-4.24683e-07, -3.16713e-06, -1.23643e-05) bones/40/position = Vector3(2.25983, 9.10828, 0.517866) -bones/40/rotation = Quaternion(0.190553, -0.00191066, 0.0330006, 0.98112) +bones/40/rotation = Quaternion(0.220996, -0.00142798, 0.0332105, 0.974708) bones/41/position = Vector3(5.8333e-07, 6.3235e-07, 1.57826e-05) -bones/42/rotation = Quaternion(0.0903997, 7.32054e-08, 0.0110174, 0.995845) +bones/42/rotation = Quaternion(0.117654, 3.11304e-08, 0.014339, 0.992951) bones/43/position = Vector3(-1.30539e-06, 1.28774e-05, 4.90486e-08) -bones/44/rotation = Quaternion(0.134768, -7.61413e-08, 0.0164247, 0.990741) +bones/44/rotation = Quaternion(0.211996, -3.89194e-08, 0.0258367, 0.976929) bones/45/position = Vector3(-2.28086e-07, -1.45823e-06, -4.29744e-07) bones/48/position = Vector3(2.68185, 2.4648, 1.57399) -bones/48/rotation = Quaternion(0.123738, 0.0614859, -0.162114, 0.97705) +bones/48/rotation = Quaternion(0.123908, 0.0616255, -0.156299, 0.977967) bones/49/position = Vector3(-3.57628e-06, -1.16825e-05, 6.73833e-06) bones/50/position = Vector3(-7.17277e-06, 4.18897, 1.07578e-06) -bones/50/rotation = Quaternion(-0.065068, 0.0341859, 0.191511, 0.978734) +bones/50/rotation = Quaternion(-0.0663669, 0.0359506, 0.212307, 0.974284) bones/52/position = Vector3(-8.77766e-06, 3.41628, -4.79003e-06) -bones/52/rotation = Quaternion(0.0223925, -0.00350703, -0.0584347, 0.998034) +bones/52/rotation = Quaternion(0.018407, -0.00114223, -0.0141967, 0.999729) bones/53/position = Vector3(-3.03984e-06, 2.01762e-05, -1.93187e-06) -bones/56/rotation = Quaternion(0.0531727, 0.00267766, 0.0303457, 0.998121) +bones/56/rotation = Quaternion(0.0488781, 0.0112906, -0.0536224, 0.997301) bones/57/position = Vector3(1.19211e-07, -2.28947e-05, -3.36394e-06) -bones/58/rotation = Quaternion(-0.101476, 0.020969, 0.0128598, 0.994534) +bones/58/rotation = Quaternion(-0.0586441, -0.00547983, 0.00924352, 0.998221) bones/59/position = Vector3(-1.0431e-07, -1.54506e-05, -1.49384e-06) -bones/61/rotation = Quaternion(0.576319, 0.496831, -0.542606, 0.355801) +bones/61/rotation = Quaternion(0.548466, 0.520641, -0.543615, 0.364144) bones/62/position = Vector3(5.96046e-08, -6.10948e-07, -7.88433e-06) bones/63/position = Vector3(3.42725e-07, 10.8377, 3.26269e-05) -bones/63/rotation = Quaternion(0.514101, 0.0626199, 0.0220347, 0.855157) +bones/63/rotation = Quaternion(0.616863, 0.0670184, -0.0718558, 0.780913) bones/64/position = Vector3(2.4772e-06, 1.24322e-06, 3.17702e-06) bones/65/position = Vector3(7.81477e-06, 27.8415, 3.26074e-05) -bones/65/rotation = Quaternion(-1.80993e-08, -3.41039e-08, 0.199691, 0.979859) +bones/65/rotation = Quaternion(4.07093e-08, 2.60793e-08, 0.18234, 0.983236) bones/66/position = Vector3(-3.25318e-06, -4.67625e-06, -1.50252e-06) -bones/67/rotation = Quaternion(0.0551003, 0.135529, 0.0470682, 0.98812) +bones/67/rotation = Quaternion(0.00915824, 0.111795, 0.0758943, 0.990787) bones/68/position = Vector3(7.47968e-08, -6.91227e-07, -2.51579e-06) -bones/69/rotation = Quaternion(0.158909, -0.0734939, 0.0529653, 0.983128) +bones/69/rotation = Quaternion(0.12462, -0.0690797, 0.111919, 0.983449) bones/70/position = Vector3(1.18017e-05, 1.18017e-05, 1.03254e-05) bones/71/position = Vector3(-7.12144e-07, 4.18709, 2.40078e-06) -bones/71/rotation = Quaternion(-0.0321456, -0.0368734, -0.198096, 0.978961) +bones/71/rotation = Quaternion(-0.0119331, 0.00344536, -0.103213, 0.994582) bones/72/position = Vector3(5.48363e-06, -9.44734e-06, -1.48937e-05) bones/73/position = Vector3(-6.19066e-06, 3.41839, -3.25305e-05) -bones/73/rotation = Quaternion(-0.00653892, -0.129599, -0.140468, 0.981545) +bones/73/rotation = Quaternion(-0.0709239, -0.0923349, -0.047557, 0.99206) bones/74/position = Vector3(3.75509e-06, 1.69277e-05, 9.12723e-07) bones/75/position = Vector3(2.59013e-06, 2.5806, 1.43079e-06) -bones/77/rotation = Quaternion(0.0945151, -0.00116771, 0.00108596, 0.995522) +bones/77/rotation = Quaternion(0.153308, -0.00218838, -0.00424038, 0.988167) bones/78/position = Vector3(2.34035e-07, 6.61208e-07, -1.22018e-06) bones/79/position = Vector3(-2.66701e-07, 3.7, -4.303e-07) -bones/79/rotation = Quaternion(0.113511, -1.25944e-07, -0.0136986, 0.993442) +bones/79/rotation = Quaternion(0.187051, -2.89049e-07, -0.0225734, 0.982091) bones/80/position = Vector3(-3.04282e-06, -2.24161e-06, -1.52532e-05) -bones/81/rotation = Quaternion(0.137959, -1.52381e-07, -0.0166491, 0.990298) +bones/81/rotation = Quaternion(0.252027, -3.30255e-07, -0.0304148, 0.967242) bones/84/position = Vector3(-1.56742e-06, -5.37828e-06, 1.60567e-05) -bones/85/rotation = Quaternion(0.0395193, -0.000171217, -0.000416618, 0.999219) +bones/85/rotation = Quaternion(0.103039, -0.00117523, -0.000971861, 0.994676) bones/86/position = Vector3(-2.09158e-07, 7.10476e-06, -1.37234e-05) -bones/87/rotation = Quaternion(0.125074, -2.31704e-07, -0.0150939, 0.992033) +bones/87/rotation = Quaternion(0.193775, -1.5408e-07, -0.0233848, 0.980767) bones/88/position = Vector3(-1.44259e-06, -2.81852e-06, -1.08586e-06) -bones/89/rotation = Quaternion(0.149466, -1.8287e-07, -0.0180375, 0.988602) +bones/89/rotation = Quaternion(0.243564, -3.82096e-07, -0.0293932, 0.969439) bones/90/position = Vector3(-1.67251e-06, -5.69229e-06, 4.16067e-06) bones/92/position = Vector3(-2.07638e-06, -8.50701e-06, 1.83102e-06) -bones/93/rotation = Quaternion(0.0934523, -0.00111243, 0.000755997, 0.995623) +bones/93/rotation = Quaternion(0.162198, -0.000588186, -0.0159881, 0.986629) bones/94/position = Vector3(-1.24702e-06, -4.42364e-06, 5.52884e-07) -bones/95/rotation = Quaternion(0.142515, -1.9556e-07, -0.0171987, 0.989643) +bones/95/rotation = Quaternion(0.181899, -2.96367e-07, -0.0219516, 0.983072) bones/96/position = Vector3(-2.19045e-06, -7.68091e-06, -2.55365e-06) bones/97/position = Vector3(1.62425e-06, 2.95, 1.38972e-05) -bones/97/rotation = Quaternion(0.21712, -3.15011e-07, -0.0262021, 0.975793) +bones/97/rotation = Quaternion(0.276315, -4.08819e-07, -0.0333458, 0.960488) bones/98/position = Vector3(-2.69965e-06, -1.43062e-07, 1.26105e-06) bones/99/position = Vector3(-2.845e-05, 2.64431, 1.98053e-06) bones/100/position = Vector3(6.57979e-07, -4.74934e-06, 1.44472e-05) bones/101/position = Vector3(3.80627, 8.07779, 0.486894) -bones/101/rotation = Quaternion(0.109405, 0.00431716, -0.0507793, 0.99269) +bones/101/rotation = Quaternion(0.164675, 0.00474566, -0.0476871, 0.985183) bones/102/position = Vector3(-2.33662e-06, 1.08604e-05, 1.6658e-05) -bones/103/rotation = Quaternion(0.123519, 0.00427894, 0.0207453, 0.992116) +bones/103/rotation = Quaternion(0.208897, 0.00734917, 0.00993022, 0.97786) bones/104/position = Vector3(1.84285e-06, 5.76279e-06, -1.71906e-05) -bones/105/rotation = Quaternion(0.0937019, -6.23296e-08, -0.0113077, 0.995536) +bones/105/rotation = Quaternion(0.229115, -3.54336e-07, -0.0276495, 0.973007) bones/106/position = Vector3(1.48522e-06, -3.60209e-06, 1.44012e-05) bones/107/position = Vector3(4.3816e-06, 2.12554, -2.07618e-05) bones/108/position = Vector3(-4.91738e-07, 8.79425e-06, -1.38031e-06) -bones/109/rotation = Quaternion(-0.0692737, 0.141006, 0.983921, 0.0849542) +bones/109/rotation = Quaternion(-0.0635143, 0.0581304, 0.992364, -0.0883157) bones/110/position = Vector3(-1.06222e-06, 3.19319e-05, -1.56533e-06) -bones/111/rotation = Quaternion(-0.295735, -0.0596685, -0.0123846, 0.953324) +bones/111/rotation = Quaternion(-0.199361, 0.0628865, 0.0152453, 0.977787) bones/112/position = Vector3(2.91388e-07, 4.25241e-06, -2.20301e-06) -bones/113/rotation = Quaternion(0.555602, -0.0142493, 0.0561636, 0.829427) -bones/115/rotation = Quaternion(0.338989, 3.45834e-05, 1.21499e-05, 0.94079) -bones/119/rotation = Quaternion(0.0140214, 0.106701, 0.989156, 0.0999454) +bones/113/rotation = Quaternion(0.534333, -0.0316787, -0.0097, 0.844625) +bones/115/rotation = Quaternion(0.341258, 3.45743e-05, 1.21829e-05, 0.93997) +bones/119/rotation = Quaternion(0.0483289, 0.146858, 0.980692, -0.119748) bones/120/position = Vector3(-8.23132e-07, -4.34501e-06, -1.59527e-06) -bones/121/rotation = Quaternion(-0.250538, -0.0735148, 0.00494552, 0.965299) +bones/121/rotation = Quaternion(-0.325496, -0.0556083, -0.0153673, 0.943782) bones/122/position = Vector3(-6.62286e-07, 6.482e-06, 2.36121e-07) -bones/123/rotation = Quaternion(0.534216, -0.139986, 0.120867, 0.824869) -bones/125/rotation = Quaternion(0.342195, -0.0134352, -0.00466826, 0.939521) +bones/123/rotation = Quaternion(0.577067, -0.0254236, 0.00072291, 0.816301) +bones/125/rotation = Quaternion(0.325482, 3.70683e-05, 1.36367e-05, 0.945548) + +[node name="InteractionArea" type="Area3D" parent="."] +transform = Transform3D(2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 1.5, 0.5) +script = ExtResource("5_nujwx") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractionArea"] +shape = SubResource("SphereShape3D_cvkom") + +[connection signal="area_entered" from="InteractionArea" to="InteractionArea" method="_on_area_entered"] +[connection signal="area_exited" from="InteractionArea" to="InteractionArea" method="_on_area_exited"] [editable path="PlayerMesh"] diff --git a/godot/src/interactable.ts b/godot/src/interactable.ts new file mode 100644 index 0000000..cc6cb82 --- /dev/null +++ b/godot/src/interactable.ts @@ -0,0 +1,8 @@ +import { Area3D } from 'godot' +import Interactor from './interactor' + +export default class Interactable extends Area3D { + interact(interactor: Interactor) { + console.log('awawawawawa', interactor) + } +} diff --git a/godot/src/interactor.ts b/godot/src/interactor.ts new file mode 100644 index 0000000..de3d200 --- /dev/null +++ b/godot/src/interactor.ts @@ -0,0 +1,44 @@ +import { Area3D } from 'godot' +import Interactable from './interactable' + +class InteractableDistance { + interactable: Interactable + distance: number + + constructor(interactable: Interactable, distance: number) { + this.interactable = interactable + this.distance = distance + } +} + +export default class Interactor extends Area3D { + _interactables: Array = [] + + _on_area_entered(area: Area3D) { + if (area instanceof Interactable) { + this._interactables.push(area) + } + } + + _on_area_exited(area: Area3D) { + const index = this._interactables.indexOf(area as Interactable) + + if (index) { + this._interactables.splice(index, 1) + } + } + + try_interact_nearest() { + // @ts-ignore + this._interactables.reduce(this.find_nearest.bind(this)) + } + + find_nearest(nearest: InteractableDistance, target: Interactable): InteractableDistance { + const distance = this.global_position.distance_to(target.global_position) + if (distance < nearest.distance) { + return new InteractableDistance(target, distance) + } else { + return nearest + } + } +} diff --git a/godot/src/player.ts b/godot/src/player.ts index db4df53..9acd925 100644 --- a/godot/src/player.ts +++ b/godot/src/player.ts @@ -4,6 +4,7 @@ import PlayerInput from './player_input' import MessageBus from './message_bus' import DebugDraw from './debug_draw' import { CameraCache } from './camera_cache' +import Interactor from './interactor' export default class Player extends CharacterBody3D { gravity = ProjectSettings.get_setting('physics/3d/default_gravity') @@ -12,6 +13,10 @@ export default class Player extends CharacterBody3D { player_input!: NodePath _player_input!: PlayerInput + @export_(Variant.Type.TYPE_NODE_PATH) + interactor!: NodePath + _interactor!: Interactor + is_running() { return this._player_input.is_running } @help('Forward walk speed in units per second') @@ -42,6 +47,17 @@ export default class Player extends CharacterBody3D { this.update_camera ) ) + + this._player_input.interact.connect( + Callable.create( + this, + this.try_interact + ) + ) + } + + try_interact() { + } update_camera(cam: Camera3D) { diff --git a/godot/src/player_input.ts b/godot/src/player_input.ts index 75e2960..b5df34d 100644 --- a/godot/src/player_input.ts +++ b/godot/src/player_input.ts @@ -1,5 +1,5 @@ -import { float64, Input, InputEvent, InputEventJoypadButton, InputEventJoypadMotion, InputEventKey, InputEventMouse, int32, Node3D, PackedVector2Array, Variant } from 'godot' -import { export_ } from 'godot.annotations' +import { float64, Input, InputEvent, InputEventJoypadButton, InputEventJoypadMotion, InputEventKey, InputEventMouse, int32, Node3D, Signal0, Signal1, Variant } from 'godot' +import { export_, signal } from 'godot.annotations' import InputBuffer from './input_buffer' enum Device { @@ -31,6 +31,18 @@ export default class PlayerInput extends Node3D { return this._running } + @signal() + readonly run!: Signal1 + + _interacting: boolean = false + + get is_interacting() { + return this._interacting + } + + @signal() + readonly interact!: Signal0 + private _changed_since_last_frame = false get changed_since_last_frame() { @@ -41,13 +53,26 @@ export default class PlayerInput extends Node3D { this._input_buffer = new InputBuffer(this.input_buffer_size) } - _process(delta: float64): void { + _process(_delta: float64): void { const next_input = Input.get_vector('move_left', 'move_right', 'move_forward', 'move_back') this._changed_since_last_frame = !next_input.is_equal_approx(this.movement_input) this._input_buffer.push(next_input) - this._running = Input.is_action_pressed('run') + + const running = Input.is_action_pressed('run') + + if (running !== this._running) { + this._running = running + this.run.emit(running) + } + + const interacting = Input.is_action_pressed('interact') + + if (interacting !== this._interacting) { + this._interacting = interacting + this.interact.emit() + } } _input(event: InputEvent): void {