From a16ea0cd152d6f7d6ae7c2c567c51869357b926f Mon Sep 17 00:00:00 2001 From: ncusimano Date: Sun, 20 Aug 2023 15:43:03 -0600 Subject: [PATCH] Slimes Turn When Stuck :) --- godot/Level/Island.tscn | 4 ++-- godot/Models/grape_man.tscn | 12 +++--------- godot/player.tscn | 8 ++------ godot/slime_shared.gd | 20 ++++++++++++++++++++ godot/slime_shared.tscn | 2 ++ 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/godot/Level/Island.tscn b/godot/Level/Island.tscn index 053cf95..0d1d8fb 100644 --- a/godot/Level/Island.tscn +++ b/godot/Level/Island.tscn @@ -23,9 +23,9 @@ [ext_resource type="PackedScene" uid="uid://b3aus2kigf8xt" path="res://Models/beach_decor/cooler.tscn" id="24_sl7ne"] [ext_resource type="PackedScene" uid="uid://cft26nug7kyqb" path="res://ambient_light_1.tscn" id="25_novxt"] [ext_resource type="PackedScene" path="res://color_cube.tscn" id="25_rm0cr"] -[ext_resource type="PackedScene" uid="uid://d2pvg0f5jtpve" path="res://slime_kill_box.tscn" id="27_cjxk6"] +[ext_resource type="PackedScene" path="res://slime_kill_box.tscn" id="27_cjxk6"] [ext_resource type="PackedScene" uid="uid://bw3k2c75qavce" path="res://Models/beach_decor/bucket.tscn" id="27_f3p1i"] -[ext_resource type="PackedScene" uid="uid://6ycop5t3nra5" path="res://Level/World/DayNightEnvironment.tscn" id="27_jutn4"] +[ext_resource type="PackedScene" path="res://Level/World/DayNightEnvironment.tscn" id="27_jutn4"] [ext_resource type="PackedScene" uid="uid://g4gmc0pwlak1" path="res://Models/buildings/fence.tscn" id="28_prydb"] [sub_resource type="Animation" id="Animation_jpnyu"] diff --git a/godot/Models/grape_man.tscn b/godot/Models/grape_man.tscn index 759ad10..bee880f 100644 --- a/godot/Models/grape_man.tscn +++ b/godot/Models/grape_man.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=42 format=3 uid="uid://bgoo1lbt28na"] +[gd_scene load_steps=41 format=3 uid="uid://bgoo1lbt28na"] [ext_resource type="PackedScene" uid="uid://bhanbx2dyhv2d" path="res://Models/grape_man.glb" id="1_fh5yr"] [ext_resource type="Script" path="res://Models/grape_man.gd" id="2_ksje8"] @@ -6,7 +6,6 @@ [ext_resource type="AudioStream" uid="uid://baocyd0p3jcku" path="res://Sounds/pickup_grunt.ogg" id="4_nvurj"] [ext_resource type="AudioStream" uid="uid://b80t5xqckjoqk" path="res://Sounds/heartychuckle.ogg" id="5_b32re"] [ext_resource type="AudioStream" uid="uid://0mhkf1ls1wcn" path="res://Sounds/sadsound.ogg" id="6_qe4bi"] -[ext_resource type="AudioStream" uid="uid://bmocmgq06o6f5" path="res://Sounds/footstep.ogg" id="7_b2ik0"] [sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_a0vxm"] filters = ["rig/Skeleton3D:forearm.L", "rig/Skeleton3D:forearm.R", "rig/Skeleton3D:head", "rig/Skeleton3D:upper_arm.L", "rig/Skeleton3D:upper_arm.R"] @@ -155,7 +154,7 @@ transform = Transform3D(0.065, 0, 0, 0, 0.065, 0, 0, 0, 0.065, 0, 0, 0) script = ExtResource("2_ksje8") [node name="Skeleton3D" parent="rig" index="0"] -bones/0/rotation = Quaternion(0.0733902, 0, 0, 0.997303) +bones/0/rotation = Quaternion(0.0664168, 0, 0, 0.997792) bones/1/rotation = Quaternion(-0.0891896, 1.18734e-07, -1.06322e-08, 0.996015) bones/2/rotation = Quaternion(0.0133933, -1.19199e-07, 1.5966e-09, 0.99991) bones/3/rotation = Quaternion(-0.00997737, 0.100365, -0.694951, 0.711948) @@ -170,7 +169,6 @@ bones/15/rotation = Quaternion(0.105246, -0.0039338, 0.0113526, 0.994374) [node name="OmniLight3D" type="OmniLight3D" parent="." index="2"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.289473, 8.26292, 4.26359) -light_energy = 0.5 [node name="AnimationTree" type="AnimationTree" parent="." index="3"] tree_root = SubResource("AnimationNodeStateMachine_6mfdu") @@ -193,9 +191,5 @@ stream = ExtResource("5_b32re") [node name="sad" type="AudioStreamPlayer" parent="." index="7"] stream = ExtResource("6_qe4bi") -[node name="soundboard" type="AudioStreamPlayer" parent="." index="8"] +[node name="woohoo" type="AudioStreamPlayer" parent="." index="8"] stream = ExtResource("6_qe4bi") - -[node name="footstep" type="AudioStreamPlayer" parent="." index="9"] -stream = ExtResource("7_b2ik0") -volume_db = -10.0 diff --git a/godot/player.tscn b/godot/player.tscn index 576fad1..4b969c4 100644 --- a/godot/player.tscn +++ b/godot/player.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://7utef1nnena8"] +[gd_scene load_steps=6 format=3 uid="uid://7utef1nnena8"] [ext_resource type="Script" path="res://Player.gd" id="1_7gpdp"] [ext_resource type="PackedScene" uid="uid://bgoo1lbt28na" path="res://Models/grape_man.tscn" id="2_ctyy5"] [ext_resource type="Script" path="res://Holster.gd" id="3_a68da"] -[ext_resource type="PackedScene" uid="uid://cbca7q18ae42h" path="res://UI/PauseMenu.tscn" id="4_kcqpl"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_kb4ms"] radius = 0.0669067 @@ -25,7 +24,7 @@ shape = SubResource("CapsuleShape3D_kb4ms") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.389874, 0) [node name="PlayerCam" type="Camera3D" parent="CameraMount"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.930216) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.643936) current = true fov = 50.0 @@ -38,9 +37,6 @@ script = ExtResource("3_a68da") transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0.0672282, 0) shape = SubResource("SphereShape3D_6l1w6") -[node name="PauseMenu" parent="." instance=ExtResource("4_kcqpl")] -visible = false - [connection signal="anim_check_grab" from="grape_man" to="." method="_on_grape_man_anim_check_grab"] [connection signal="body_entered" from="Holster/Area3D" to="." method="_on_holster_enter"] [connection signal="body_exited" from="Holster/Area3D" to="." method="_on_holster_exit"] diff --git a/godot/slime_shared.gd b/godot/slime_shared.gd index 0465a66..ebed2f2 100644 --- a/godot/slime_shared.gd +++ b/godot/slime_shared.gd @@ -22,11 +22,18 @@ var task = "idle" # Margin of accuracy to which the character will correct their direction when off course (radians). @export var dir_accuracy = deg_to_rad(0.1) +var wall_timer + # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") func _ready(): $slime.idle() + wall_timer = Timer.new() + wall_timer.wait_time = 5 + wall_timer.one_shot = true + wall_timer.timeout.connect(_on_timer_timeout) + add_child(wall_timer) func walk(): $slime.walk() @@ -43,6 +50,9 @@ func walk(): target_location_xz = location_xz task = "idle" + if !wall_timer.is_stopped(): + wall_timer.stop() + func spin(): # Continue to correct direction to within a margin of dir_accuracy degrees. if direction_xz.angle_to(target_direction_xz) >= dir_accuracy: @@ -59,6 +69,7 @@ func idle(): if task <= walk_chance: task = "walk" target_location_xz = transform.origin * Vector3(1, 0, 1) + (direction_xz * 4) + wall_timer.start() # 6% chance to rotate. elif task > walk_chance and task <= (walk_chance + spin_chance): task = "spin" @@ -68,6 +79,15 @@ func idle(): # 90% chance to idle. elif task > (spin_chance + walk_chance): task = "idle" + +# Stops walking if cannot reach destination in 5 sec. +func _on_timer_timeout(): + # Try to turn around before walking again. + if task == "walk": + task = "spin" + var rotation_angle = rng.randf_range(-2*PI, 2*PI) + var rotation_vector = Vector3(cos(rotation_angle), 0, sin(rotation_angle)) + target_direction_xz = direction_xz + rotation_vector # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): diff --git a/godot/slime_shared.tscn b/godot/slime_shared.tscn index 1c473d5..075b92a 100644 --- a/godot/slime_shared.tscn +++ b/godot/slime_shared.tscn @@ -15,3 +15,5 @@ transform = Transform3D(0.035, 0, 0, 0, 0.035, 0, 0, 0, 0.035, 0, 0, 0) [node name="slime_collision" type="CollisionShape3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0408143, 0) shape = SubResource("SphereShape3D_k5rhc") + +[node name="IsTrappedOnWall" type="Timer" parent="."]