From 1a14c78ede65c9aab4e7dbeca974e3e54aa790e5 Mon Sep 17 00:00:00 2001 From: Morph01 <145839520+Morph01@users.noreply.github.com> Date: Fri, 16 Aug 2024 19:17:51 +0200 Subject: [PATCH] Zombies with PathFinding Run and Attack ! --- godot/Scenes/Characters/zombie.tscn | 108 ++++++++++++++++------------ godot/Scenes/Levels/world.tscn | 10 ++- src/Zombie.cpp | 32 ++++++--- src/Zombie.h | 10 ++- 4 files changed, 103 insertions(+), 57 deletions(-) diff --git a/godot/Scenes/Characters/zombie.tscn b/godot/Scenes/Characters/zombie.tscn index d8ee93c..0ff2593 100644 --- a/godot/Scenes/Characters/zombie.tscn +++ b/godot/Scenes/Characters/zombie.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=22 format=3 uid="uid://bjuf33f7oteit"] +[gd_scene load_steps=25 format=3 uid="uid://bjuf33f7oteit"] [ext_resource type="Texture2D" uid="uid://yrlrk74j3no" path="res://Assets/Models/Characters/zombie_mremireh_body__diffuse.png" id="1_xkx2p"] [ext_resource type="Texture2D" uid="uid://byrx1euloda3v" path="res://Assets/Models/Characters/zombie_mremireh_body_normal.png" id="2_0tyam"] @@ -926,6 +926,7 @@ tracks/93/keys = PackedFloat32Array(0, 1, 1.8974e-06, 23.512, -4.82143e-06) [sub_resource type="Animation" id="Animation_d74yk"] resource_name = "Run" length = 0.833333 +loop_mode = 1 tracks/0/type = "position_3d" tracks/0/imported = true tracks/0/enabled = true @@ -2258,16 +2259,32 @@ _data = { radius = 0.4 height = 1.9 +[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_jonj8"] +animation = &"Attack" + [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_30aa1"] animation = &"Run" [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_kxil8"] advance_mode = 2 +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_0aqh6"] +xfade_time = 0.2 +advance_mode = 2 +advance_condition = &"attack" + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_r4c6y"] +xfade_time = 0.2 +switch_mode = 2 +advance_mode = 2 +advance_condition = &"run" + [sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_v7c1i"] +states/Attack/node = SubResource("AnimationNodeAnimation_jonj8") +states/Attack/position = Vector2(456, 100) states/Run/node = SubResource("AnimationNodeAnimation_30aa1") -states/Run/position = Vector2(312, 109) -transitions = ["Start", "Run", SubResource("AnimationNodeStateMachineTransition_kxil8")] +states/Run/position = Vector2(332, 100) +transitions = ["Start", "Run", SubResource("AnimationNodeStateMachineTransition_kxil8"), "Run", "Attack", SubResource("AnimationNodeStateMachineTransition_0aqh6"), "Attack", "Run", SubResource("AnimationNodeStateMachineTransition_r4c6y")] [node name="zombie" type="Zombie"] @@ -2279,43 +2296,43 @@ bones/0/name = "mixamorig_Hips" bones/0/parent = -1 bones/0/rest = Transform3D(1, -1.64104e-06, -1.23603e-07, 1.23603e-07, 0, 1, -1.64104e-06, -1, 0, -0.0301997, 0.410377, -103.255) bones/0/enabled = true -bones/0/position = Vector3(0.310187, 0.431141, -82.5511) -bones/0/rotation = Quaternion(-0.72332, -0.00243253, 0.021771, 0.690166) +bones/0/position = Vector3(0.511112, -1.22466, -91.7131) +bones/0/rotation = Quaternion(-0.62284, -0.125654, 0.106214, 0.764853) bones/0/scale = Vector3(1, 1, 1) bones/1/name = "mixamorig_Spine" bones/1/parent = 0 bones/1/rest = Transform3D(1, 1.64209e-06, 1.08946e-07, -1.64105e-06, 0.99996, -0.0089287, -1.23603e-07, 0.0089287, 0.99996, -0.0024263, 12.7776, 0.315252) bones/1/enabled = true bones/1/position = Vector3(-0.00242631, 12.7775, 0.315252) -bones/1/rotation = Quaternion(0.351657, -0.00792476, 0.0777737, 0.932859) +bones/1/rotation = Quaternion(0.30719, -0.0963365, 0.090708, 0.942404) bones/1/scale = Vector3(1, 1, 1) bones/2/name = "mixamorig_Spine1" bones/2/parent = 1 bones/2/rest = Transform3D(1, -8.12885e-12, -3.90108e-14, 8.12895e-12, 0.999989, 0.0046898, 8.87653e-16, -0.0046898, 0.999989, 2.71058e-09, 8.79264, 1.49012e-07) bones/2/enabled = true bones/2/position = Vector3(2.71058e-09, 8.79264, 1.49012e-07) -bones/2/rotation = Quaternion(0.0615718, -0.0110645, 0.0181263, 0.997877) +bones/2/rotation = Quaternion(0.072533, -0.0407277, 0.0173466, 0.996383) bones/2/scale = Vector3(1, 1, 1) bones/3/name = "mixamorig_Spine2" bones/3/parent = 2 bones/3/rest = Transform3D(1, -3.75935e-18, -2.14464e-21, 3.75932e-18, 0.999991, 0.00423897, -1.37911e-20, -0.00423897, 0.999991, 2.498e-16, 8.65112, -5.96046e-08) bones/3/enabled = true bones/3/position = Vector3(2.498e-16, 8.65112, -5.96046e-08) -bones/3/rotation = Quaternion(0.0622219, -0.010082, 0.0165404, 0.997874) +bones/3/rotation = Quaternion(0.0732063, -0.0411665, 0.0145504, 0.996361) bones/3/scale = Vector3(1, 1, 1) bones/4/name = "mixamorig_Neck" bones/4/parent = 3 bones/4/rest = Transform3D(1, -6.70873e-21, -7.44903e-23, 6.70874e-21, 1, 1.98848e-08, 7.44902e-23, -1.98848e-08, 1, -3.72529e-09, 21.2425, -0.842534) bones/4/enabled = true bones/4/position = Vector3(-3.34159e-06, 21.2425, -0.842529) -bones/4/rotation = Quaternion(-0.0505679, 0.0238406, -0.0190878, 0.998254) +bones/4/rotation = Quaternion(-0.0412098, 0.0316679, -0.00952378, 0.998603) bones/4/scale = Vector3(1, 1, 1) bones/5/name = "mixamorig_Head" bones/5/parent = 4 bones/5/rest = Transform3D(1, -6.68473e-21, 3.2708e-23, 6.68473e-21, 1, 0, -3.2708e-23, 0, 1, 4.28824e-15, 20.4181, 4.8338) bones/5/enabled = true bones/5/position = Vector3(4.28824e-15, 20.4181, 4.8338) -bones/5/rotation = Quaternion(-0.310126, 0.129469, -0.0897227, 0.937555) +bones/5/rotation = Quaternion(-0.322696, 0.168696, -0.074468, 0.928366) bones/5/scale = Vector3(1, 1, 1) bones/6/name = "mixamorig_HeadTop_End" bones/6/parent = 5 @@ -2343,28 +2360,28 @@ bones/9/parent = 3 bones/9/rest = Transform3D(-0.0117089, 0.982404, -0.1864, 0.00222149, -0.186386, -0.982474, -0.999929, -0.0119177, 0, 6.57015, 17.5956, -2.76176) bones/9/enabled = true bones/9/position = Vector3(6.57023, 17.5956, -2.76177) -bones/9/rotation = Quaternion(-0.579999, -0.420144, 0.575252, -0.395177) +bones/9/rotation = Quaternion(-0.544049, -0.434001, 0.620431, -0.361551) bones/9/scale = Vector3(1, 1, 1) bones/10/name = "mixamorig_LeftArm" bones/10/parent = 9 bones/10/rest = Transform3D(0.999929, -0.011709, -0.00222139, 0.0119178, 0.982404, 0.186385, -8.03266e-08, -0.186399, 0.982474, -4.47035e-08, 12.1385, 5.01977e-06) bones/10/enabled = true bones/10/position = Vector3(8.15145e-06, 12.1385, -2.43421e-06) -bones/10/rotation = Quaternion(0.155181, -0.0431495, 0.261516, 0.951665) +bones/10/rotation = Quaternion(0.137568, -0.210903, 0.438749, 0.862609) bones/10/scale = Vector3(1, 1, 1) bones/11/name = "mixamorig_LeftForeArm" bones/11/parent = 10 bones/11/rest = Transform3D(1, 9.44764e-09, -8.19156e-09, -9.44763e-09, 1, 8.04663e-07, 8.19157e-09, -8.04663e-07, 1, 1.05432e-07, 18.4696, 1.60245e-05) bones/11/enabled = true bones/11/position = Vector3(3.94925e-06, 18.4696, -6.70776e-06) -bones/11/rotation = Quaternion(-5.3325e-07, 1.13099e-07, 0.252679, 0.96755) +bones/11/rotation = Quaternion(-4.13952e-07, 7.64241e-08, 0.234086, 0.972216) bones/11/scale = Vector3(1, 1, 1) bones/12/name = "mixamorig_LeftHand" bones/12/parent = 11 bones/12/rest = Transform3D(1, -8.07957e-09, 8.07957e-09, 8.07957e-09, 1, -5.6028e-14, -8.07957e-09, 5.60933e-14, 1, 2.0646e-07, 29.5088, 1.52078e-05) bones/12/enabled = true bones/12/position = Vector3(5.71921e-06, 29.5088, -7.52443e-06) -bones/12/rotation = Quaternion(0.00425196, -0.455129, 0.103903, 0.884332) +bones/12/rotation = Quaternion(0.0852503, -0.357107, 0.112002, 0.923397) bones/12/scale = Vector3(1, 1, 1) bones/13/name = "mixamorig_LeftHandThumb1" bones/13/parent = 12 @@ -2399,14 +2416,14 @@ bones/17/parent = 12 bones/17/rest = Transform3D(1, -1.40998e-06, -1.3975e-07, 1.40998e-06, 1, 5.20607e-06, 1.39742e-07, -5.20607e-06, 1, -6.40379, 26.4943, -0.17099) bones/17/enabled = true bones/17/position = Vector3(-6.40379, 26.4943, -0.171004) -bones/17/rotation = Quaternion(-0.0545965, -6.44228e-07, 0.00659322, 0.998487) +bones/17/rotation = Quaternion(-0.0374808, -4.19283e-07, 0.00452944, 0.999287) bones/17/scale = Vector3(1, 1, 1) bones/18/name = "mixamorig_LeftHandIndex2" bones/18/parent = 17 bones/18/rest = Transform3D(1, -5.7191e-08, 5.71908e-08, 5.71911e-08, 1, -2.17708e-06, -5.71907e-08, 2.17708e-06, 1, 5.78031e-07, 8.79287, 1.14833e-05) bones/18/enabled = true bones/18/position = Vector3(5.78031e-07, 8.79287, 1.14833e-05) -bones/18/rotation = Quaternion(0.367124, 4.81139e-08, -0.0442688, 0.929118) +bones/18/rotation = Quaternion(0.37774, -7.22376e-08, -0.045549, 0.924791) bones/18/scale = Vector3(1, 1, 1) bones/19/name = "mixamorig_LeftHandIndex3" bones/19/parent = 18 @@ -2420,7 +2437,7 @@ bones/20/parent = 12 bones/20/rest = Transform3D(1, -2.53799e-07, -1.03828e-07, 2.53798e-07, 1, -4.87293e-06, 1.03829e-07, 4.87293e-06, 1, 0.00151853, 25.7911, 0.0166931) bones/20/enabled = true bones/20/position = Vector3(0.00151402, 25.7911, 0.0166754) -bones/20/rotation = Quaternion(-0.059187, -8.42716e-07, 0.00714704, 0.998221) +bones/20/rotation = Quaternion(-0.04508, -5.77318e-07, 0.00544596, 0.998969) bones/20/scale = Vector3(1, 1, 1) bones/21/name = "mixamorig_LeftHandMiddle2" bones/21/parent = 20 @@ -2483,28 +2500,28 @@ bones/29/parent = 3 bones/29/rest = Transform3D(-0.0117083, -0.982396, 0.186444, -0.00222197, -0.186431, -0.982465, 0.999929, -0.0119172, -1.19209e-07, -6.57016, 17.5959, -2.76177) bones/29/enabled = true bones/29/position = Vector3(-6.57024, 17.5958, -2.76175) -bones/29/rotation = Quaternion(0.568425, -0.426811, 0.574894, 0.405242) +bones/29/rotation = Quaternion(0.568932, -0.428463, 0.570247, 0.409334) bones/29/scale = Vector3(1, 1, 1) bones/30/name = "mixamorig_RightArm" bones/30/parent = 29 bones/30/rest = Transform3D(0.999929, 0.0117084, 0.00222177, -0.0119174, 0.982396, 0.186427, 1.14669e-07, -0.186441, 0.982466, 2.98023e-08, 12.1386, 1.29775e-05) bones/30/enabled = true bones/30/position = Vector3(-8.08837e-06, 12.1386, 4.88866e-07) -bones/30/rotation = Quaternion(0.22744, 0.335912, -0.416009, 0.813862) +bones/30/rotation = Quaternion(0.374335, 0.287259, -0.223695, 0.852828) bones/30/scale = Vector3(1, 1, 1) bones/31/name = "mixamorig_RightForeArm" bones/31/parent = 30 bones/31/rest = Transform3D(1, 2.20824e-09, -1.29789e-09, -2.20823e-09, 1, 4.64471e-06, 1.2979e-09, -4.64471e-06, 1, -2.66512e-07, 18.4696, -1.55792e-05) bones/31/enabled = true bones/31/position = Vector3(-4.14816e-07, 18.4696, -1.2969e-06) -bones/31/rotation = Quaternion(-2.19186e-06, -6.21338e-07, -0.266341, 0.963879) +bones/31/rotation = Quaternion(-2.28761e-06, -7.54028e-07, -0.319818, 0.947479) bones/31/scale = Vector3(1, 1, 1) bones/32/name = "mixamorig_RightHand" bones/32/parent = 31 bones/32/rest = Transform3D(1, 3.41881e-08, -3.41881e-08, -3.41882e-08, 1, -1.15386e-06, 3.41881e-08, 1.15386e-06, 1, 1.73907e-07, 29.5089, 3.67749e-06) bones/32/enabled = true bones/32/position = Vector3(1.03968e-05, 29.5089, 1.38965e-06) -bones/32/rotation = Quaternion(0.0703434, 0.338492, -0.143889, 0.927238) +bones/32/rotation = Quaternion(0.0801559, 0.245004, -0.0784431, 0.963013) bones/32/scale = Vector3(1, 1, 1) bones/33/name = "mixamorig_RightHandThumb1" bones/33/parent = 32 @@ -2539,14 +2556,14 @@ bones/37/parent = 32 bones/37/rest = Transform3D(1, 1.19311e-06, 6.31644e-08, -1.19311e-06, 1, 6.37229e-07, -6.31636e-08, -6.37229e-07, 1, 6.40379, 26.4943, -0.171003) bones/37/enabled = true bones/37/position = Vector3(6.40379, 26.4943, -0.171003) -bones/37/rotation = Quaternion(-0.157254, 1.31876e-06, -0.0191583, 0.987372) +bones/37/rotation = Quaternion(-0.125853, 1.09405e-06, -0.0153343, 0.99193) bones/37/scale = Vector3(1, 1, 1) bones/38/name = "mixamorig_RightHandIndex2" bones/38/parent = 37 bones/38/rest = Transform3D(1, 7.46894e-08, 9.95477e-08, -7.46894e-08, 1, -4.63684e-10, -9.95477e-08, 4.63676e-10, 1, -1.26993e-07, 8.79249, -1.4677e-05) bones/38/enabled = true bones/38/position = Vector3(5.79147e-06, 8.7925, 4.06897e-06) -bones/38/rotation = Quaternion(0.108441, 3.59547e-08, 0.0132056, 0.994015) +bones/38/rotation = Quaternion(0.1495, 8.30591e-09, 0.0182057, 0.988594) bones/38/scale = Vector3(1, 1, 1) bones/39/name = "mixamorig_RightHandIndex3" bones/39/parent = 38 @@ -2623,28 +2640,28 @@ bones/49/parent = 0 bones/49/rest = Transform3D(-1, -1.61224e-06, 4.29343e-08, 1.60665e-06, -0.993503, 0.113804, -1.40823e-07, 0.113804, 0.993502, 11.3941, -6.1878, -0.41386) bones/49/enabled = true bones/49/position = Vector3(11.3941, -6.18784, -0.413819) -bones/49/rotation = Quaternion(0.0412334, 0.556037, 0.827264, -0.0689679) +bones/49/rotation = Quaternion(-0.000149511, 0.289775, 0.95494, -0.0641861) bones/49/scale = Vector3(1, 1, 0.999998) bones/50/name = "mixamorig_LeftLeg" bones/50/parent = 49 bones/50/rest = Transform3D(1, 6.94812e-08, -1.06469e-07, -4.11865e-08, 0.969334, 0.245744, 1.20279e-07, -0.245744, 0.969335, -3.44336e-07, 32.5338, 4.70383e-05) bones/50/enabled = true bones/50/position = Vector3(1.32505e-07, 32.5338, 5.50832e-06) -bones/50/rotation = Quaternion(-0.803993, -0.0461324, 0.0537815, 0.590402) +bones/50/rotation = Quaternion(-0.754409, -0.0027234, 0.0907397, 0.650097) bones/50/scale = Vector3(1, 1, 1) bones/51/name = "mixamorig_LeftFoot" bones/51/parent = 50 bones/51/rest = Transform3D(0.977152, -0.211548, -0.0205252, 0.0806816, 0.458539, -0.885004, 0.196632, 0.863127, 0.465131, -1.98803e-07, 48.648, 1.91926e-07) bones/51/enabled = true bones/51/position = Vector3(5.52994e-07, 48.648, -6.43921e-07) -bones/51/rotation = Quaternion(0.52934, -0.0449537, 0.121529, 0.838456) +bones/51/rotation = Quaternion(0.372341, -0.0242441, 0.137021, 0.917606) bones/51/scale = Vector3(1, 1, 1) bones/52/name = "mixamorig_LeftToeBase" bones/52/parent = 51 bones/52/rest = Transform3D(0.994305, -0.00805927, -0.106271, -0.0542637, 0.819927, -0.569891, 0.091727, 0.572412, 0.81482, -2.03601e-05, 29, 1.81803e-05) bones/52/enabled = true bones/52/position = Vector3(-3.57033e-07, 29, -7.04998e-07) -bones/52/rotation = Quaternion(0.396432, -0.194093, -0.0475999, 0.896049) +bones/52/rotation = Quaternion(0.548781, -0.473532, 0.0117362, 0.688817) bones/52/scale = Vector3(1, 1, 1) bones/53/name = "mixamorig_LeftToe_End" bones/53/parent = 52 @@ -2658,28 +2675,28 @@ bones/54/parent = 0 bones/54/rest = Transform3D(-1, -1.61224e-06, 4.29171e-08, 1.60665e-06, -0.993503, 0.113804, -1.40841e-07, 0.113804, 0.993502, -11.3941, -6.18776, -0.413858) bones/54/enabled = true bones/54/position = Vector3(-11.3941, -6.1878, -0.413816) -bones/54/rotation = Quaternion(-0.0755778, 0.441748, 0.885113, 0.12539) +bones/54/rotation = Quaternion(-0.0650039, 0.540434, 0.830059, 0.121279) bones/54/scale = Vector3(1, 1, 0.999998) bones/55/name = "mixamorig_RightLeg" bones/55/parent = 54 bones/55/rest = Transform3D(1, 6.94846e-08, -1.06487e-07, -4.11853e-08, 0.969334, 0.245744, 1.20297e-07, -0.245744, 0.969335, -3.44467e-07, 32.5338, 5.8359e-05) bones/55/enabled = true bones/55/position = Vector3(-3.44461e-07, 32.5338, -3.08126e-07) -bones/55/rotation = Quaternion(-0.691654, -0.03751, 0.00601703, 0.721229) +bones/55/rotation = Quaternion(-0.559186, 0.0374126, -0.0167958, 0.828027) bones/55/scale = Vector3(1, 1, 1) bones/56/name = "mixamorig_RightFoot" bones/56/parent = 55 bones/56/rest = Transform3D(0.977152, 0.211549, 0.0205261, -0.0806797, 0.458533, -0.885007, -0.196634, 0.863131, 0.465124, 7.5487e-07, 48.6481, -4.9512e-06) bones/56/enabled = true bones/56/position = Vector3(-4.00578e-07, 48.6481, 1.98047e-06) -bones/56/rotation = Quaternion(0.664426, 0.10764, -0.0152366, 0.739404) +bones/56/rotation = Quaternion(0.506113, 0.0885424, -0.0351858, 0.857189) bones/56/scale = Vector3(1, 1, 1) bones/57/name = "mixamorig_RightToeBase" bones/57/parent = 56 bones/57/rest = Transform3D(0.994304, 0.00805453, 0.106272, 0.0542684, 0.819927, -0.56989, -0.0917255, 0.572412, 0.81482, -6.79173e-06, 29, 9.25874e-06) bones/57/enabled = true bones/57/position = Vector3(1.58658e-06, 29, 4.79121e-07) -bones/57/rotation = Quaternion(0.344115, 0.0612848, 0.0124463, 0.936843) +bones/57/rotation = Quaternion(0.30443, 0.052937, 0.0121634, 0.950985) bones/57/scale = Vector3(1, 1, 1) bones/58/name = "mixamorig_RightToe_End" bones/58/parent = 57 @@ -2698,11 +2715,11 @@ mesh = SubResource("ArrayMesh_kq2p3") skin = SubResource("Skin_igf26") [node name="Physical Bone mixamorig_Hips" type="PhysicalBone3D" parent="Armature/Skeleton3D"] -transform = Transform3D(-0.998216, 0.0418237, 0.0275661, -0.0409079, -0.997335, 0.0226912, 0.0284695, 0.0214512, 0.999153, 0.13421, 0.286198, -88.9339) +transform = Transform3D(-0.942272, 0.331034, 0.0141296, -0.324466, -0.91685, -0.224247, -0.0610218, -0.215898, 0.974179, 0.425233, 0.206005, -97.9361) collision_layer = 2 collision_mask = 2 -joint_offset = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.000121663, 8.49366e-06, 6.38821) -body_offset = Transform3D(-0.999432, 0.00769927, 0.000188166, -6.50552e-06, 0.0246753, -0.999486, -0.00736948, -0.998108, -0.0246631, -0.00108051, 6.38493, 0.157562) +joint_offset = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00354876, -0.00311005, 6.38745) +body_offset = Transform3D(-0.998418, 0.00770226, 0.000187956, -2.91094e-05, 0.0246755, -0.999451, -0.00643983, -0.998069, -0.0246625, 0.00236654, 6.38403, 0.154449) bone_name = "mixamorig_Hips" [node name="CollisionShape3D" type="CollisionShape3D" parent="Armature/Skeleton3D/Physical Bone mixamorig_Hips"] @@ -2710,12 +2727,12 @@ transform = Transform3D(1, 3.72529e-08, -2.98023e-08, 0, -2.98023e-08, 1, 0, -1, shape = SubResource("CapsuleShape3D_6sdfw") [node name="Physical Bone mixamorig_Head" type="PhysicalBone3D" parent="Armature/Skeleton3D"] -transform = Transform3D(-0.966851, -0.236202, 0.0965952, 0.198058, -0.933318, -0.298809, 0.160962, -0.270415, 0.948194, -14.9274, 50.8066, -147.465) +transform = Transform3D(-0.983845, 0.0719589, 0.162906, -0.160654, -0.754287, -0.635367, 0.0772825, -0.65223, 0.752923, -27.5224, 70.1711, -125.494) collision_layer = 2 collision_mask = 2 joint_type = 1 -joint_offset = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00114586, -0.0021615, 17.5358) -body_offset = Transform3D(-0.999969, 4.97699e-06, -6.58855e-05, 1.64285e-05, 0.143811, -0.98851, 3.01003e-06, -0.989604, -0.14331, 9.53674e-06, 17.3346, 2.51091) +joint_offset = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.48596, 24.872, 11.7749) +body_offset = Transform3D(-0.982919, -0.164101, -0.0814859, 0.0160078, 0.366602, -0.928906, 0.182614, -0.915535, -0.357234, 12.3991, 1.69977, 25.6106) bone_name = "mixamorig_Head" joint_constraints/bias = 0.3 joint_constraints/damping = 1.0 @@ -2726,12 +2743,12 @@ transform = Transform3D(1, -1.86265e-09, -7.45058e-09, 7.45058e-09, -1.49012e-08 shape = SubResource("CapsuleShape3D_06hh8") [node name="Physical Bone mixamorig_LeftLeg" type="PhysicalBone3D" parent="Armature/Skeleton3D"] -transform = Transform3D(-0.958987, 0.283337, 0.00761281, 0.231779, 0.76843, 0.59645, 0.163147, 0.573762, -0.802603, 16.17, 16.6261, -46.5882) +transform = Transform3D(-0.974651, -0.168512, -0.146309, -0.21142, 0.486983, 0.847038, -0.0715292, 0.856424, -0.51058, 2.43222, -7.51742, -40.6364) collision_layer = 2 collision_mask = 2 joint_type = 1 -joint_offset = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000112495, 0.00162727, 24.3257) -body_offset = Transform3D(0.999997, -2.86102e-06, 6.25849e-07, -5.06639e-07, 1.46925e-05, -0.999993, -3.27826e-07, 0.999984, -2.32458e-06, 9.72748e-05, 24.3256, -0.0015707) +joint_offset = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10.6579, -3.87023, 21.6732) +body_offset = Transform3D(0.928466, 0.180682, -0.324066, -0.256313, -0.319091, -0.912122, -0.268357, 0.929809, -0.250181, 17.6183, 15.8019, 6.1607) bone_name = "mixamorig_LeftLeg" joint_constraints/bias = 0.3 joint_constraints/damping = 1.0 @@ -2742,12 +2759,12 @@ transform = Transform3D(1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0) shape = SubResource("CapsuleShape3D_t3iic") [node name="Physical Bone mixamorig_RightLeg" type="PhysicalBone3D" parent="Armature/Skeleton3D"] -transform = Transform3D(-0.970203, -0.242094, -0.0109041, -0.21006, 0.81755, 0.536197, -0.120901, 0.522487, -0.844044, -20.3798, 12.2416, -37.6024) +transform = Transform3D(-0.854698, -0.511911, 0.0846936, -0.211405, 0.492682, 0.844156, -0.473972, 0.703634, -0.529204, -30.4555, -16.2204, -50.377) collision_layer = 2 collision_mask = 2 joint_type = 1 -joint_offset = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.00127e-05, 0.00109388, 24.3264) -body_offset = Transform3D(1.00002, 6.4075e-07, -5.0813e-06, 4.01586e-06, 2.83122e-06, -1.00002, -2.47657e-05, 0.999995, 9.44734e-06, 0.000213623, 24.3269, -0.0013237) +joint_offset = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0440102, 0.672031, 36.0786) +body_offset = Transform3D(0.894626, -0.0617347, -0.442401, -0.308337, 0.631373, -0.711362, 0.323147, 0.772947, 0.545964, 15.9633, 25.2542, -20.2313) bone_name = "mixamorig_RightLeg" joint_constraints/bias = 0.3 joint_constraints/damping = 1.0 @@ -2767,9 +2784,12 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) shape = SubResource("CapsuleShape3D_go447") [node name="NavigationAgent3D" type="NavigationAgent3D" parent="."] -path_height_offset = 0.35 +path_height_offset = 0.6 [node name="AnimationTree" type="AnimationTree" parent="."] +reset_on_save = false root_motion_track = NodePath("Armature/Skeleton3D:mixamorig_Hips") tree_root = SubResource("AnimationNodeStateMachine_v7c1i") anim_player = NodePath("../AnimationPlayer") +parameters/conditions/attack = false +parameters/conditions/run = false diff --git a/godot/Scenes/Levels/world.tscn b/godot/Scenes/Levels/world.tscn index 0338e1f..5af5a4d 100644 --- a/godot/Scenes/Levels/world.tscn +++ b/godot/Scenes/Levels/world.tscn @@ -4,7 +4,7 @@ [ext_resource type="Texture2D" uid="uid://b8n5rff2a8h2u" path="res://Assets/Textures/Black.png" id="2_fkwcn"] [ext_resource type="Texture2D" uid="uid://lpbttkw7gpxj" path="res://Assets/Textures/Orange.png" id="3_ux02w"] [ext_resource type="Texture2D" uid="uid://di3uyny341483" path="res://Assets/Textures/Green.png" id="4_wp15n"] -[ext_resource type="PackedScene" uid="uid://bcawyy7lmwphr" path="res://Scenes/Characters/zombie.tscn" id="5_4vmh3"] +[ext_resource type="PackedScene" uid="uid://bjuf33f7oteit" path="res://Scenes/Characters/zombie.tscn" id="5_4vmh3"] [ext_resource type="PackedScene" uid="uid://d38w4ae3qj0k4" path="res://Scenes/Characters/first_person_player.tscn" id="5_8ctht"] [sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_6c4vd"] @@ -106,4 +106,12 @@ shape = SubResource("ConcavePolygonShape3D_rit6o") m_PlayerPath = NodePath("../../FirstPersonPlayer") transform = Transform3D(-0.98774, 0, -0.156107, 0, 1, 0, 0.156107, 0, -0.98774, 0, 0, 7.38477) +[node name="zombie2" parent="Map" instance=ExtResource("5_4vmh3")] +m_PlayerPath = NodePath("../../FirstPersonPlayer") +transform = Transform3D(-0.98774, 0, -0.156107, 0, 1, 0, 0.156107, 0, -0.98774, 8.0927, 0, 7.38477) + +[node name="zombie3" parent="Map" instance=ExtResource("5_4vmh3")] +m_PlayerPath = NodePath("../../FirstPersonPlayer") +transform = Transform3D(-0.98774, 0, -0.156107, 0, 1, 0, 0.156107, 0, -0.98774, 14.3905, 0, -18.3684) + [node name="FirstPersonPlayer" parent="." instance=ExtResource("5_8ctht")] diff --git a/src/Zombie.cpp b/src/Zombie.cpp index 7a7f335..0b2ab70 100644 --- a/src/Zombie.cpp +++ b/src/Zombie.cpp @@ -1,14 +1,13 @@ #include "Zombie.h" #include -#include using namespace godot; namespace blitz { static constexpr float SPEED = 2.0f; - +static constexpr float ATTACK_RANGE = 2.0f; void Zombie::_bind_methods() { ClassDB::bind_method(D_METHOD("set_m_PlayerPath", "m_PlayerPath"), &Zombie::set_m_PlayerPath); @@ -32,7 +31,11 @@ void Zombie::_ready() { DEV_ASSERT(m_Player); m_NavigationAgent = Object::cast_to(find_child("NavigationAgent3D")); DEV_ASSERT(m_NavigationAgent); - m_Velocity = Vector3(0, 0, 0); + m_AnimationTree = Object::cast_to(find_child("AnimationTree")); + DEV_ASSERT(m_AnimationTree); + m_StateMachine = Object::cast_to(m_AnimationTree->get("parameters/playback")); + DEV_ASSERT(m_StateMachine); + this->set_velocity(Vector3(0, 0, 0)); } void Zombie::_process(float a_Delta) { @@ -41,15 +44,26 @@ void Zombie::_process(float a_Delta) { return; } #endif - this->set_velocity(m_Velocity); - m_NavigationAgent->set_target_position(m_Player->get_global_position()); - Vector3 next_nav_point = m_NavigationAgent->get_next_path_position(); - m_Velocity = (next_nav_point - get_global_position()).normalized() * SPEED; - this->set_velocity(m_Velocity); - look_at(Vector3(m_Player->get_global_position().x, get_global_position().y, m_Player->get_global_position().z), Vector3(0, 1, 0)); + if (m_StateMachine->get_current_node().match("Run")) { + m_NavigationAgent->set_target_position(m_Player->get_global_position()); + m_Velocity = (m_NavigationAgent->get_next_path_position() - this->get_global_position()).normalized() * SPEED; + this->set_velocity(m_Velocity); + look_at(Vector3(this->get_global_position().x + this->get_velocity().x, this->get_global_position().y, + this->get_global_position().z + this->get_velocity().z)); + } else if (m_StateMachine->get_current_node().match("Attack")) { + this->set_velocity(Vector3(0, 0, 0)); + look_at(Vector3(m_Player->get_global_position().x, m_Player->get_global_position().y / 2, m_Player->get_global_position().z)); + } + m_AnimationTree->set("parameters/conditions/run", !_target_in_range()); + m_AnimationTree->set("parameters/conditions/attack", _target_in_range()); + move_and_slide(); } +bool Zombie::_target_in_range() { + return this->get_global_position().distance_to(m_Player->get_global_position()) < ATTACK_RANGE; +} + void Zombie::set_m_PlayerPath(const NodePath& path) { m_PlayerPath = path; } diff --git a/src/Zombie.h b/src/Zombie.h index efd74a9..2bf0815 100644 --- a/src/Zombie.h +++ b/src/Zombie.h @@ -1,12 +1,14 @@ #pragma once +#include "FirstPersonPlayer.h" +#include +#include #include #include #include -#include "FirstPersonPlayer.h" - namespace blitz { + class Zombie : public godot::CharacterBody3D { GDCLASS(Zombie, godot::CharacterBody3D) protected: @@ -18,15 +20,17 @@ class Zombie : public godot::CharacterBody3D { void _ready(); void _process(float delta); + bool _target_in_range(); private: godot::NavigationAgent3D* m_NavigationAgent; FirstPersonPlayer* m_Player; godot::NodePath m_PlayerPath; godot::Vector3 m_Velocity; + godot::AnimationTree* m_AnimationTree; + godot::AnimationNodeStateMachinePlayback* m_StateMachine; void set_m_PlayerPath(const godot::NodePath& path); - godot::NodePath get_m_PlayerPath() const; };