From c187a2aacca28d0a1d869543a31f531b1d95bdb4 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Mon, 30 Sep 2024 18:02:20 +0200 Subject: [PATCH] Interactions now differ depending on action type defined in Item resource. --- assets/characters/rogue.tscn | 81 +++++++++++++++++++++++++++++------- data/items/axe.tres | 1 + data/items/dagger.tres | 1 + data/items/sword.tres | 1 + data/items/wrench.tres | 2 + model/item.gd | 1 + objects/player.gd | 11 ++++- objects/player.tscn | 2 +- 8 files changed, 82 insertions(+), 18 deletions(-) diff --git a/assets/characters/rogue.tscn b/assets/characters/rogue.tscn index 42eefad..2b5d726 100644 --- a/assets/characters/rogue.tscn +++ b/assets/characters/rogue.tscn @@ -1,11 +1,54 @@ -[gd_scene load_steps=15 format=3 uid="uid://dy8vjf760prhq"] +[gd_scene load_steps=24 format=3 uid="uid://dy8vjf760prhq"] [ext_resource type="PackedScene" uid="uid://c0ot1kp5fekqy" path="res://assets/3rdparty/KayKit_Adventurers_1.0_EXTRA/Characters/gltf/Rogue.glb" id="1_rsxsi"] [ext_resource type="AnimationLibrary" uid="uid://dbaynxuqbkor6" path="res://assets/characters/rogue_animation_library.tres" id="2_18sv4"] -[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_fe868"] +[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_duxpv"] animation = &"rogue/1H_Melee_Attack_Chop" +[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_njp2v"] +animation = &"rogue/1H_Melee_Attack_Slice_Diagonal" + +[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_go27t"] +animation = &"rogue/Unarmed_Melee_Attack_Kick" + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_glihl"] +advance_mode = 2 +advance_condition = &"tool_action_chop" + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_qm71c"] +priority = 2 +advance_mode = 2 + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_t6she"] +advance_mode = 2 +advance_condition = &"tool_action_slice" + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_oq6xv"] +reset = false +switch_mode = 2 +advance_mode = 2 + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_5ovo5"] +reset = false +switch_mode = 2 +advance_mode = 2 + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_kjkqd"] +reset = false +switch_mode = 2 +advance_mode = 2 + +[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_bqf2d"] +states/Start/position = Vector2(142, 162) +states/rogue_1H_Melee_Attack_Chop/node = SubResource("AnimationNodeAnimation_duxpv") +states/rogue_1H_Melee_Attack_Chop/position = Vector2(490, 58) +states/rogue_1H_Melee_Attack_Slice_Diagonal/node = SubResource("AnimationNodeAnimation_njp2v") +states/rogue_1H_Melee_Attack_Slice_Diagonal/position = Vector2(480, 162) +states/rogue_Unarmed_Melee_Attack_Kick/node = SubResource("AnimationNodeAnimation_go27t") +states/rogue_Unarmed_Melee_Attack_Kick/position = Vector2(485, 257) +transitions = ["Start", "rogue_1H_Melee_Attack_Chop", SubResource("AnimationNodeStateMachineTransition_glihl"), "Start", "rogue_Unarmed_Melee_Attack_Kick", SubResource("AnimationNodeStateMachineTransition_qm71c"), "Start", "rogue_1H_Melee_Attack_Slice_Diagonal", SubResource("AnimationNodeStateMachineTransition_t6she"), "rogue_1H_Melee_Attack_Chop", "End", SubResource("AnimationNodeStateMachineTransition_oq6xv"), "rogue_Unarmed_Melee_Attack_Kick", "End", SubResource("AnimationNodeStateMachineTransition_5ovo5"), "rogue_1H_Melee_Attack_Slice_Diagonal", "End", SubResource("AnimationNodeStateMachineTransition_kjkqd")] + [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_dqt6d"] animation = &"rogue/Idle" @@ -25,14 +68,6 @@ node_connections = [&"TimeScale", 0, &"Animation", &"output", 0, &"TimeScale"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ryaua"] advance_mode = 2 -[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_1dwt2"] -advance_mode = 2 -advance_condition = &"attack" - -[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_w1i70"] -switch_mode = 2 -advance_mode = 2 - [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_chmuj"] xfade_time = 0.1 advance_mode = 2 @@ -43,22 +78,31 @@ xfade_time = 0.1 advance_mode = 2 advance_condition = &"idle" -[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_2nd5h"] +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_7j7mm"] +xfade_time = 0.1 +advance_mode = 2 +advance_condition = &"interact" + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_6s34y"] +switch_mode = 2 +advance_mode = 2 + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_g3yva"] xfade_time = 0.2 advance_mode = 2 advance_condition = &"running" [sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_h0y4b"] states/End/position = Vector2(902, 102) +states/Interact/node = SubResource("AnimationNodeStateMachine_bqf2d") +states/Interact/position = Vector2(694, 123) states/Start/position = Vector2(189, 123) -states/rogue_1H_Melee_Attack_Chop/node = SubResource("AnimationNodeAnimation_fe868") -states/rogue_1H_Melee_Attack_Chop/position = Vector2(677, 123) states/rogue_Idle/node = SubResource("AnimationNodeAnimation_dqt6d") states/rogue_Idle/position = Vector2(422, 123) states/running/node = SubResource("AnimationNodeBlendTree_uc6vu") states/running/position = Vector2(422, 285) -transitions = ["Start", "rogue_Idle", SubResource("AnimationNodeStateMachineTransition_ryaua"), "rogue_Idle", "rogue_1H_Melee_Attack_Chop", SubResource("AnimationNodeStateMachineTransition_1dwt2"), "rogue_1H_Melee_Attack_Chop", "rogue_Idle", SubResource("AnimationNodeStateMachineTransition_w1i70"), "rogue_Idle", "running", SubResource("AnimationNodeStateMachineTransition_chmuj"), "running", "rogue_Idle", SubResource("AnimationNodeStateMachineTransition_oa1w1"), "rogue_1H_Melee_Attack_Chop", "running", SubResource("AnimationNodeStateMachineTransition_2nd5h")] -graph_offset = Vector2(-12, -72) +transitions = ["Start", "rogue_Idle", SubResource("AnimationNodeStateMachineTransition_ryaua"), "rogue_Idle", "running", SubResource("AnimationNodeStateMachineTransition_chmuj"), "running", "rogue_Idle", SubResource("AnimationNodeStateMachineTransition_oa1w1"), "rogue_Idle", "Interact", SubResource("AnimationNodeStateMachineTransition_7j7mm"), "Interact", "rogue_Idle", SubResource("AnimationNodeStateMachineTransition_6s34y"), "Interact", "running", SubResource("AnimationNodeStateMachineTransition_g3yva")] +graph_offset = Vector2(-12, 57.7514) [node name="Rogue" type="Node3D"] @@ -72,9 +116,14 @@ libraries = { [node name="AnimationTree" type="AnimationTree" parent="."] root_node = NodePath("../Rogue") +libraries = { +"rogue": ExtResource("2_18sv4") +} tree_root = SubResource("AnimationNodeStateMachine_h0y4b") anim_player = NodePath("../AnimationPlayer") -parameters/conditions/attack = false parameters/conditions/idle = false +parameters/conditions/interact = false parameters/conditions/running = false +parameters/Interact/conditions/tool_action_chop = false +parameters/Interact/conditions/tool_action_slice = false parameters/running/TimeScale/scale = 1.5 diff --git a/data/items/axe.tres b/data/items/axe.tres index 2f9524c..d9822c9 100644 --- a/data/items/axe.tres +++ b/data/items/axe.tres @@ -12,3 +12,4 @@ icon = ExtResource("1_dlqed") max_stack_size = 1 is_tool = true is_buildable = false +tool_action = 1 diff --git a/data/items/dagger.tres b/data/items/dagger.tres index dd46aea..ff16c92 100644 --- a/data/items/dagger.tres +++ b/data/items/dagger.tres @@ -12,3 +12,4 @@ icon = ExtResource("1_afk8v") max_stack_size = 1 is_tool = true is_buildable = false +tool_action = 2 diff --git a/data/items/sword.tres b/data/items/sword.tres index 308a090..3d11907 100644 --- a/data/items/sword.tres +++ b/data/items/sword.tres @@ -12,3 +12,4 @@ icon = ExtResource("1_gprhx") max_stack_size = 1 is_tool = true is_buildable = false +tool_action = 2 diff --git a/data/items/wrench.tres b/data/items/wrench.tres index 72517f8..5ce8f9e 100644 --- a/data/items/wrench.tres +++ b/data/items/wrench.tres @@ -12,3 +12,5 @@ scene = ExtResource("2_8uss6") icon = ExtResource("1_b5epx") max_stack_size = 1 is_tool = true +is_buildable = false +tool_action = 1 diff --git a/model/item.gd b/model/item.gd index 35aebb5..475490b 100644 --- a/model/item.gd +++ b/model/item.gd @@ -7,3 +7,4 @@ extends Resource @export var max_stack_size:int = 1 @export var is_tool:bool = false @export var is_buildable:bool = false +@export_enum("None", "Chop", "Slice") var tool_action: int = 0 diff --git a/objects/player.gd b/objects/player.gd index 17681b6..a37e09c 100644 --- a/objects/player.gd +++ b/objects/player.gd @@ -24,7 +24,7 @@ signal trigger_message(message:String) var interaction_state:bool = false func _process(_delta): - animation_tree.set("parameters/conditions/attack", interaction_state) + animation_tree.set("parameters/conditions/interact", interaction_state) if interaction_state: interaction_state = false @@ -82,6 +82,15 @@ func set_right_hand_item(item:Item) -> void: right_hand_attachement.add_child(item.scene.instantiate()) current_tool = item + animation_tree.set("parameters/Interact/conditions/tool_action_slice", false) + animation_tree.set("parameters/Interact/conditions/tool_action_chop", false) + + match item.tool_action: + 1: + animation_tree.set("parameters/Interact/conditions/tool_action_chop", true) + 2: + animation_tree.set("parameters/Interact/conditions/tool_action_slice", true) + func has_build_tool_active() -> bool: if current_tool and current_tool.name == "Pickaxe": return true diff --git a/objects/player.tscn b/objects/player.tscn index 306c12a..761e09a 100644 --- a/objects/player.tscn +++ b/objects/player.tscn @@ -32,7 +32,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.470516, 0) shape = SubResource("CapsuleShape3D_7kfad") [node name="RightHandBone" type="BoneAttachment3D" parent="."] -transform = Transform3D(-0.000803348, -0.063443, 0.394936, 0.399985, -0.00336239, 0.000273371, 0.00327666, 0.394922, 0.0634475, -0.196151, 0.251476, 0.0431326) +transform = Transform3D(-0.00015721, -0.0606496, 0.395375, 0.399999, -0.000666146, 5.67707e-05, 0.000649959, 0.395375, 0.0606499, -0.196425, 0.255346, 0.0425267) bone_name = "Knife" bone_idx = 17 use_external_skeleton = true