From b844984aed8542ead116300f82bf8fb219b8e75d Mon Sep 17 00:00:00 2001 From: LUCASTUCIOUS Date: Mon, 22 Jul 2024 22:14:04 +0200 Subject: [PATCH] Walking in Animation Tree --- maps/gym.tscn | 8 +- player.gd | 5 + player.tscn | 197 +++++++++++++++++++++----------- player/animations/WalkLeft.res | 3 + player/animations/WalkRight.res | 3 + player/animations/idle.res | 4 +- player/currentCloth.tres | 4 +- player/currentHat.tres | 4 +- 8 files changed, 149 insertions(+), 79 deletions(-) create mode 100644 player/animations/WalkLeft.res create mode 100644 player/animations/WalkRight.res diff --git a/maps/gym.tscn b/maps/gym.tscn index fede0a7..95ff34f 100644 --- a/maps/gym.tscn +++ b/maps/gym.tscn @@ -8,7 +8,7 @@ [sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_dixrq"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_bjsqx"] -size = Vector2(64.4614, 47.0722) +size = Vector2(43.3023, 13.4486) [node name="Gym" type="Node2D"] y_sort_enabled = true @@ -18,18 +18,18 @@ environment = SubResource("Environment_iaiy2") camera_attributes = SubResource("CameraAttributesPractical_dixrq") [node name="player" parent="." instance=ExtResource("1_mkpg2")] -position = Vector2(490, 44) +position = Vector2(966, 130) floor_constant_speed = true [node name="StaticBody2D" type="StaticBody2D" parent="."] [node name="TreeSwamp01Sprt" type="Sprite2D" parent="StaticBody2D"] z_as_relative = false -position = Vector2(0, -993) +position = Vector2(0, -895) scale = Vector2(4.06445, 4.06445) texture = ExtResource("2_hscig") [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] -position = Vector2(-3.8147e-06, -133) +position = Vector2(21, -127.669) scale = Vector2(4.06445, 4.06445) shape = SubResource("RectangleShape2D_bjsqx") diff --git a/player.gd b/player.gd index a0bda13..43ce6b8 100644 --- a/player.gd +++ b/player.gd @@ -23,5 +23,10 @@ func _physics_process(delta): else: velocity.y = move_toward(velocity.y, 0, SPEED) #endregion + + var WalkLeft = directionX < 0 + $AnimationTree.set("parameters/Locomotion/conditions/Idle",(velocity.x == 0 and velocity.y == 0)) + $AnimationTree.set("parameters/Locomotion/conditions/WalkLeft",velocity.x != 0) + move_and_slide() diff --git a/player.tscn b/player.tscn index 06193b6..35b079b 100644 --- a/player.tscn +++ b/player.tscn @@ -1,13 +1,14 @@ -[gd_scene load_steps=22 format=3 uid="uid://0m1hk2nu4bps"] +[gd_scene load_steps=19 format=3 uid="uid://0m1hk2nu4bps"] [ext_resource type="Script" path="res://player.gd" id="1_0pgv8"] [ext_resource type="Texture2D" uid="uid://5pmqr3y62guu" path="res://player/currentCloth.tres" id="2_45h8h"] [ext_resource type="Animation" uid="uid://b85dikp6ps8i2" path="res://player/animations/idle.res" id="2_ymiw5"] +[ext_resource type="Animation" uid="uid://2woypk4u40b5" path="res://player/animations/WalkLeft.res" id="3_2eohq"] [ext_resource type="Texture2D" uid="uid://5qixrbrclydr" path="res://player/currentHat.tres" id="3_qyf3b"] [ext_resource type="Texture2D" uid="uid://sod0ms1cfkjf" path="res://player/playerSkin_ref.png" id="4_ytgpb"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_kapu3"] -size = Vector2(192, 256) +size = Vector2(192, 148) [sub_resource type="Animation" id="Animation_oktsg"] length = 0.001 @@ -166,67 +167,139 @@ tracks/13/keys = { "points": PackedFloat32Array(0, -0.25, 0, 0.25, 0), "times": PackedFloat32Array(0) } +tracks/14/type = "bezier" +tracks/14/imported = false +tracks/14/enabled = true +tracks/14/path = NodePath("Skeleton2D/root/Hips:position:x") +tracks/14/interp = 1 +tracks/14/loop_wrap = true +tracks/14/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(-18, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/15/type = "bezier" +tracks/15/imported = false +tracks/15/enabled = true +tracks/15/path = NodePath("Skeleton2D/root/Hips:position:y") +tracks/15/interp = 1 +tracks/15/loop_wrap = true +tracks/15/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(-93, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/16/type = "bezier" +tracks/16/imported = false +tracks/16/enabled = true +tracks/16/path = NodePath("Skeleton2D/root/Hips/LegLeft:position:x") +tracks/16/interp = 1 +tracks/16/loop_wrap = true +tracks/16/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(77, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/17/type = "bezier" +tracks/17/imported = false +tracks/17/enabled = true +tracks/17/path = NodePath("Skeleton2D/root/Hips/LegLeft:position:y") +tracks/17/interp = 1 +tracks/17/loop_wrap = true +tracks/17/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(52, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/18/type = "bezier" +tracks/18/imported = false +tracks/18/enabled = true +tracks/18/path = NodePath("Skeleton2D/root/Hips/LegLeft:rotation") +tracks/18/interp = 1 +tracks/18/loop_wrap = true +tracks/18/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/19/type = "bezier" +tracks/19/imported = false +tracks/19/enabled = true +tracks/19/path = NodePath("Skeleton2D/root/Hips/LegRight:rotation") +tracks/19/interp = 1 +tracks/19/loop_wrap = true +tracks/19/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/20/type = "bezier" +tracks/20/imported = false +tracks/20/enabled = true +tracks/20/path = NodePath("Skeleton2D/root/Hips/LegRight:position:x") +tracks/20/interp = 1 +tracks/20/loop_wrap = true +tracks/20/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(-36, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} +tracks/21/type = "bezier" +tracks/21/imported = false +tracks/21/enabled = true +tracks/21/path = NodePath("Skeleton2D/root/Hips/LegRight:position:y") +tracks/21/interp = 1 +tracks/21/loop_wrap = true +tracks/21/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(45, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} [sub_resource type="AnimationLibrary" id="AnimationLibrary_4k813"] _data = { "RESET": SubResource("Animation_oktsg"), +"WalkLeft": ExtResource("3_2eohq"), "idle": ExtResource("2_ymiw5") } [sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_hn1cf"] -[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_1x8ew"] +[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_myrjl"] +animation = &"WalkLeft" + +[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_dx8h8"] animation = &"idle" -[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_vrcgu"] -animation = &"player_WalkLeft" +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ogkr4"] +advance_mode = 2 -[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_giw8e"] -animation = &"player_WalkRight" - -[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ylw4m"] +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_q2u5u"] advance_mode = 2 advance_condition = &"WalkLeft" -[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_tx8bg"] +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_0oq83"] advance_mode = 2 advance_condition = &"Idle" -[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_flw2n"] -advance_mode = 2 -advance_condition = &"Idle" - -[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_um8f6"] -advance_mode = 2 -advance_condition = &"WalkRight" - -[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ks6oc"] -advance_mode = 2 - [sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_x16w7"] states/BlendTree/node = SubResource("AnimationNodeBlendTree_hn1cf") states/BlendTree/position = Vector2(668, 238) states/End/position = Vector2(328, 289) -states/Start/position = Vector2(585, 52) -states/idle/node = SubResource("AnimationNodeAnimation_1x8ew") -states/idle/position = Vector2(343, 98) -states/player_WalkLeft/node = SubResource("AnimationNodeAnimation_vrcgu") -states/player_WalkLeft/position = Vector2(224, 185) -states/player_WalkRight/node = SubResource("AnimationNodeAnimation_giw8e") -states/player_WalkRight/position = Vector2(451, 185) -transitions = ["idle", "player_WalkLeft", SubResource("AnimationNodeStateMachineTransition_ylw4m"), "player_WalkLeft", "idle", SubResource("AnimationNodeStateMachineTransition_tx8bg"), "player_WalkRight", "idle", SubResource("AnimationNodeStateMachineTransition_flw2n"), "idle", "player_WalkRight", SubResource("AnimationNodeStateMachineTransition_um8f6"), "Start", "player_WalkRight", SubResource("AnimationNodeStateMachineTransition_ks6oc")] -graph_offset = Vector2(-101, 1) +states/Start/position = Vector2(371, 25) +states/WalkLeft/node = SubResource("AnimationNodeAnimation_myrjl") +states/WalkLeft/position = Vector2(534, 122) +states/idle/node = SubResource("AnimationNodeAnimation_dx8h8") +states/idle/position = Vector2(371, 111) +transitions = ["Start", "idle", SubResource("AnimationNodeStateMachineTransition_ogkr4"), "idle", "WalkLeft", SubResource("AnimationNodeStateMachineTransition_q2u5u"), "WalkLeft", "idle", SubResource("AnimationNodeStateMachineTransition_0oq83")] +graph_offset = Vector2(-48, -19) [sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_wgp38"] -graph_offset = Vector2(-281.833, 96.4845) nodes/Locomotion/node = SubResource("AnimationNodeStateMachine_x16w7") -nodes/Locomotion/position = Vector2(120, 140) -nodes/output/position = Vector2(340, 140) +nodes/Locomotion/position = Vector2(180, 120) +nodes/output/position = Vector2(380, 120) node_connections = [&"output", 0, &"Locomotion"] -[sub_resource type="LabelSettings" id="LabelSettings_dgcsv"] -font_size = 50 - [sub_resource type="CanvasTexture" id="CanvasTexture_2b3h6"] diffuse_texture = ExtResource("4_ytgpb") @@ -234,7 +307,7 @@ diffuse_texture = ExtResource("4_ytgpb") script = ExtResource("1_0pgv8") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] -position = Vector2(0, -129) +position = Vector2(0, -75) shape = SubResource("RectangleShape2D_kapu3") [node name="Camera2D" type="Camera2D" parent="."] @@ -258,75 +331,59 @@ tree_root = SubResource("AnimationNodeBlendTree_wgp38") anim_player = NodePath("../AnimationPlayer") parameters/Locomotion/conditions/Idle = false parameters/Locomotion/conditions/WalkLeft = false -parameters/Locomotion/conditions/WalkRight = false - -[node name="debug" type="Label" parent="."] -anchors_preset = 7 -anchor_left = 0.5 -anchor_top = 1.0 -anchor_right = 0.5 -anchor_bottom = 1.0 -offset_left = -188.5 -offset_top = -801.0 -offset_right = 188.5 -offset_bottom = -680.0 -grow_horizontal = 2 -grow_vertical = 0 -auto_translate = false -localize_numeral_system = false -text = "debug" -label_settings = SubResource("LabelSettings_dgcsv") -horizontal_alignment = 1 -vertical_alignment = 1 [node name="Skeleton2D" type="Skeleton2D" parent="."] position = Vector2(17, 0) [node name="BootL" type="Sprite2D" parent="Skeleton2D"] -position = Vector2(42, -41) +position = Vector2(39.7013, -40.9008) +rotation = -0.509857 +scale = Vector2(1, 1) texture = ExtResource("2_45h8h") region_enabled = true region_rect = Rect2(896, 768, 128, 128) [node name="BootR" type="Sprite2D" parent="Skeleton2D"] -position = Vector2(-71, -48) +position = Vector2(-69.1147, -47.8842) +rotation = 0.472078 +scale = Vector2(1, 1) texture = ExtResource("2_45h8h") region_enabled = true region_rect = Rect2(896, 768, 128, 128) [node name="Body" type="Sprite2D" parent="Skeleton2D"] -position = Vector2(51, -227.086) +position = Vector2(51, -222) texture = ExtResource("2_45h8h") offset = Vector2(-15, 0) region_enabled = true region_rect = Rect2(0, 640, 384, 384) [node name="HandL" type="Sprite2D" parent="Skeleton2D/Body"] -position = Vector2(-21.1837, 56.4427) +position = Vector2(33, 58) texture = ExtResource("2_45h8h") region_enabled = true region_rect = Rect2(768, 768, 128, 128) [node name="HandR" type="Sprite2D" parent="Skeleton2D/Body"] show_behind_parent = true -position = Vector2(-153.296, 34.1959) +position = Vector2(-151, 31) texture = ExtResource("2_45h8h") region_enabled = true region_rect = Rect2(768, 768, 128, 128) [node name="Tail" type="Sprite2D" parent="Skeleton2D/Body"] show_behind_parent = true -position = Vector2(44, 97.0863) -rotation = -0.0492555 -scale = Vector2(1, 1) +position = Vector2(44, 92) +scale = Vector2(0.999991, 0.999991) texture = ExtResource("2_45h8h") offset = Vector2(70, 0) region_enabled = true region_rect = Rect2(768, 640, 256, 128) [node name="Head" type="Sprite2D" parent="Skeleton2D"] -position = Vector2(-40, -400.086) -rotation = 0.0177547 +position = Vector2(-40, -395) +rotation = 0.00121922 +scale = Vector2(1, 1) texture = ExtResource("2_45h8h") offset = Vector2(0, -168) region_enabled = true @@ -334,7 +391,7 @@ region_rect = Rect2(0, 0, 512, 640) [node name="Hat" type="Sprite2D" parent="Skeleton2D/Head"] position = Vector2(65, -103) -scale = Vector2(0.60004, 0.60004) +scale = Vector2(0.600959, 0.600959) texture = ExtResource("3_qyf3b") region_enabled = true region_rect = Rect2(0, 0, 1152, 1136) @@ -349,6 +406,7 @@ rest = Transform2D(1, 0, 0, 1, -18, -93) [node name="LegLeft" type="Bone2D" parent="Skeleton2D/root/Hips"] position = Vector2(77, 52) +scale = Vector2(1, 1) rest = Transform2D(1, 0, 0, 1, 77, 52) [node name="RemoteTransform2D" type="RemoteTransform2D" parent="Skeleton2D/root/Hips/LegLeft"] @@ -356,6 +414,7 @@ remote_path = NodePath("../../../../BootL") [node name="LegRight" type="Bone2D" parent="Skeleton2D/root/Hips"] position = Vector2(-36, 45) +scale = Vector2(1, 1) rest = Transform2D(1, 0, 0, 1, -36, 45) [node name="RemoteTransform2D" type="RemoteTransform2D" parent="Skeleton2D/root/Hips/LegRight"] @@ -367,6 +426,7 @@ rest = Transform2D(1, 0, 0, 1, 86, -129) [node name="Head" type="Bone2D" parent="Skeleton2D/root/Hips/Spine"] position = Vector2(-91, -173) +scale = Vector2(1, 1) rest = Transform2D(1, 0, 0, 1, -91, -173) [node name="Hat" type="Bone2D" parent="Skeleton2D/root/Hips/Spine/Head"] @@ -400,7 +460,6 @@ update_scale = false [node name="Tail" type="Bone2D" parent="Skeleton2D/root/Hips"] position = Vector2(130, -37) -scale = Vector2(1, 1) rest = Transform2D(1, 0, 0, 1, 130, -37) [node name="RemoteTransform2D" type="RemoteTransform2D" parent="Skeleton2D/root/Hips/Tail"] diff --git a/player/animations/WalkLeft.res b/player/animations/WalkLeft.res new file mode 100644 index 0000000..c5ba134 --- /dev/null +++ b/player/animations/WalkLeft.res @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd8853cb7ddbfbab53f9a4454e3a97449f9b38644740f3f8219a59bd2779c47e +size 863 diff --git a/player/animations/WalkRight.res b/player/animations/WalkRight.res new file mode 100644 index 0000000..1ad3aa4 --- /dev/null +++ b/player/animations/WalkRight.res @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08c4b86d1a319b9087bce4a2ee3a0edb7fa7e8b6a45f673db61e499162f50485 +size 867 diff --git a/player/animations/idle.res b/player/animations/idle.res index f99cf75..074d6ef 100644 --- a/player/animations/idle.res +++ b/player/animations/idle.res @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b2d35003e5d3bbf9886148a79b1f64e8ab69cb440983011ce66d80fe70ca2472 -size 1400 +oid sha256:60830d024859677bd58d684d35f8b1317f1a69aa060ef02f578287fc70ef92f1 +size 1548 diff --git a/player/currentCloth.tres b/player/currentCloth.tres index f6b0291..6cbfb95 100644 --- a/player/currentCloth.tres +++ b/player/currentCloth.tres @@ -1,6 +1,6 @@ [gd_resource type="CanvasTexture" load_steps=2 format=3 uid="uid://5pmqr3y62guu"] -[ext_resource type="Texture2D" uid="uid://dptor7en7li7e" path="res://player/hermandad-black.png" id="1_bh8p5"] +[ext_resource type="Texture2D" uid="uid://dc0ryln54y2hw" path="res://player/archer.png" id="1_31kra"] [resource] -diffuse_texture = ExtResource("1_bh8p5") +diffuse_texture = ExtResource("1_31kra") diff --git a/player/currentHat.tres b/player/currentHat.tres index 0ad1e19..5a78399 100644 --- a/player/currentHat.tres +++ b/player/currentHat.tres @@ -1,6 +1,6 @@ [gd_resource type="CanvasTexture" load_steps=2 format=3 uid="uid://5qixrbrclydr"] -[ext_resource type="Texture2D" uid="uid://pkf86c0n3xig" path="res://extracted/Texture2D/Whitch Hat #62998.png" id="1_7652k"] +[ext_resource type="Texture2D" uid="uid://0m4sejstlmy7" path="res://extracted/Texture2D/Hat Glasses.png" id="1_ogipp"] [resource] -diffuse_texture = ExtResource("1_7652k") +diffuse_texture = ExtResource("1_ogipp")