cleanup state machine

linux
Sascha 2024-02-11 11:29:15 +07:00
parent 97509170e7
commit ef976286d2
12 changed files with 134 additions and 183 deletions

@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.3.0-dev.2">
<Project Sdk="Godot.NET.Sdk/4.3.0-dev.3">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>

@ -0,0 +1,9 @@
<Project Sdk="Godot.NET.Sdk/4.3.0-dev.2">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>DRPGActionGame</RootNamespace>
</PropertyGroup>
</Project>

@ -1,13 +1,13 @@
using DRPGActionGame.Player.States;
using Godot;
using static DRPGActionGame.Player.States.State;
using static DRPGActionGame.Player.States.StateFactory.States;
namespace DRPGActionGame.Player;
public partial class Player2 : CharacterBody3D
{
public const float SPEED = 5.0f;
private const float JUMP_VELOCITY = 4.5f;
public const float JUMP_VELOCITY = 9f; //4.5f;
public Vector3 Direction;
// Get the gravity from the project settings to be synced with RigidBody nodes.
@ -22,8 +22,8 @@ public partial class Player2 : CharacterBody3D
public override void _Ready() {
stateFactory = new();
Playback = (AnimationNodeStateMachinePlayback)animationTree.Get("parameters/playback");
ChangeState("idle");
ChangeState("move");
ChangeState(Idle);
ChangeState(Move);
}
public override void _PhysicsProcess(double delta)
@ -36,42 +36,22 @@ public partial class Player2 : CharacterBody3D
// Handle Jump.
if (Input.IsActionJustPressed("Jump") && IsOnFloor()) {
velocity.Y = JUMP_VELOCITY;
Playback.Travel("Jump");
ChangeState(Jump);
}
// Get the input direction and handle the movement/deceleration.
// As good practice, you should replace UI actions with custom gameplay actions.
// Vector2 inputDir = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
// Vector3 direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
Direction = new(Input.GetActionStrength("WalkLeft") - Input.GetActionStrength("WalkRight"), 0, Input.GetActionStrength("WalkUp") - Input.GetActionStrength("WalkDown"));
if (Direction != Vector3.Zero) ChangeState("move");
// if (Direction != Vector3.Zero)
// {
// velocity.X = Direction.X * SPEED;
// velocity.Z = Direction.Z * SPEED;
// playback.Travel("Walk");
// }
// else {
// velocity.X = Mathf.MoveToward(Velocity.X, 0, SPEED);
// velocity.Z = Mathf.MoveToward(Velocity.Z, 0, SPEED);
// playback.Travel("Idle");
// }
//
// Velocity = velocity;
if (Direction != Vector3.Zero && state.ChangeState == Idle) ChangeState(Move);
Velocity = velocity;
MoveAndSlide();
}
public void ChangeState(string newStateName) {
if (state != null) {
state.Exit();
state.QueueFree();
}
public void ChangeState(StateFactory.States newState) {
//Remove state if available
state?.Exit();
//Add New State
state = new StateFactory().GetState(newStateName);
state.Setup("ChangeState", Playback, this);
state.Name = newStateName;
state = new StateFactory().GetState(newState);
state.Setup(newState, Playback, this);
AddChild(state);
}
}

@ -1,4 +1,4 @@
[gd_scene load_steps=128 format=3 uid="uid://cbn878rbtj1a8"]
[gd_scene load_steps=118 format=3 uid="uid://cbn878rbtj1a8"]
[ext_resource type="Script" path="res://Player/Player2.cs" id="1_1dafw"]
[ext_resource type="Texture2D" uid="uid://ds7yw5hcveax2" path="res://Assets/KayKit_Skeletons_1.0_FREE/characters/gltf/Skeleton_Minion_skeleton_texture.png" id="2_sjwvv"]
@ -69973,54 +69973,18 @@ animation = &"Jump_Full_Long"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_g231r"]
animation = &"Walking_A"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_iv5xw"]
switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_a6iue"]
xfade_time = 0.2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_w31gn"]
xfade_time = 0.2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_p5wjn"]
xfade_time = 0.2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_q6ump"]
xfade_time = 0.2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_0xt2m"]
xfade_time = 0.2
switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_e1xvu"]
xfade_time = 0.2
switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_jqjsx"]
xfade_time = 0.2
switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_p1kyy"]
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_a1wrq"]
xfade_time = 0.2
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_v1jjm"]
states/Attack/node = SubResource("AnimationNodeAnimation_pr3um")
states/Attack/position = Vector2(693, 127)
states/End/position = Vector2(1141, 127)
states/Idle/node = SubResource("AnimationNodeAnimation_iosyq")
states/Idle/position = Vector2(436, 127)
states/Jump/node = SubResource("AnimationNodeAnimation_6gdft")
states/Jump/position = Vector2(538, 214)
states/End/position = Vector2(856, 127)
states/Start/position = Vector2(285, 127)
states/Walk/node = SubResource("AnimationNodeAnimation_g231r")
states/Walk/position = Vector2(538, 38)
transitions = ["Start", "Idle", SubResource("AnimationNodeStateMachineTransition_iv5xw"), "Idle", "Attack", SubResource("AnimationNodeStateMachineTransition_a6iue"), "Idle", "Walk", SubResource("AnimationNodeStateMachineTransition_w31gn"), "Idle", "Jump", SubResource("AnimationNodeStateMachineTransition_p5wjn"), "Walk", "Attack", SubResource("AnimationNodeStateMachineTransition_q6ump"), "Attack", "Idle", SubResource("AnimationNodeStateMachineTransition_0xt2m"), "Attack", "Walk", SubResource("AnimationNodeStateMachineTransition_e1xvu"), "Jump", "Idle", SubResource("AnimationNodeStateMachineTransition_jqjsx"), "Walk", "Jump", SubResource("AnimationNodeStateMachineTransition_p1kyy"), "Walk", "Idle", SubResource("AnimationNodeStateMachineTransition_a1wrq")]
states/attack/node = SubResource("AnimationNodeAnimation_pr3um")
states/attack/position = Vector2(693, 127)
states/idle/node = SubResource("AnimationNodeAnimation_iosyq")
states/idle/position = Vector2(437, 127)
states/jump/node = SubResource("AnimationNodeAnimation_6gdft")
states/jump/position = Vector2(538, 213)
states/move/node = SubResource("AnimationNodeAnimation_g231r")
states/move/position = Vector2(538, 38)
graph_offset = Vector2(-64, -21)
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("animationTree")]
script = ExtResource("1_1dafw")
@ -70036,56 +70000,56 @@ bones/0/parent = -1
bones/0/rest = Transform3D(1, 0, 2.38419e-07, 0, 1, 0, -2.38419e-07, 0, 1, 0, 0, 0)
bones/0/enabled = true
bones/0/position = Vector3(0, 0, 0)
bones/0/rotation = Quaternion(0, 1.19209e-07, 0, 1)
bones/0/rotation = Quaternion(0, 1.1921e-07, 0, 1)
bones/0/scale = Vector3(1, 1, 1)
bones/1/name = "hips"
bones/1/parent = 0
bones/1/rest = Transform3D(1, 0, -2.38419e-07, 0, 1, 0, 2.38419e-07, 0, 1, 0, 0.405663, 0)
bones/1/enabled = true
bones/1/position = Vector3(4.35612e-18, 0.347671, 1.03858e-24)
bones/1/rotation = Quaternion(0, -1.19209e-07, 0, 1)
bones/1/position = Vector3(0, 0.405663, 0)
bones/1/rotation = Quaternion(0, -1.1921e-07, 0, 1)
bones/1/scale = Vector3(1, 1, 1)
bones/2/name = "spine"
bones/2/parent = 1
bones/2/rest = Transform3D(1, 0, 1.42109e-14, 0, 1, 0, -1.42109e-14, 0, 1, 0, 0.191978, 0)
bones/2/enabled = true
bones/2/position = Vector3(0, 0.191978, 0)
bones/2/rotation = Quaternion(1.13525e-10, -8.46118e-09, 0.0419095, 0.999121)
bones/2/rotation = Quaternion(0, 7.10545e-15, 0, 1)
bones/2/scale = Vector3(1, 1, 1)
bones/3/name = "chest"
bones/3/parent = 2
bones/3/rest = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.374988, 0)
bones/3/enabled = true
bones/3/position = Vector3(0, 0.374988, 0)
bones/3/rotation = Quaternion(1.12659e-10, 8.4414e-09, -0.0419095, 0.999121)
bones/3/rotation = Quaternion(0, 0, 0, 1)
bones/3/scale = Vector3(1, 1, 1)
bones/4/name = "upperarm.l"
bones/4/parent = 3
bones/4/rest = Transform3D(0.0572842, 0.998357, -4.47035e-07, -3.8743e-07, 4.76837e-07, 1, 0.998357, -0.0572842, 4.17232e-07, 0.212007, 0.134132, 8.40246e-08)
bones/4/enabled = true
bones/4/position = Vector3(0.212007, 0.134132, 8.40246e-08)
bones/4/rotation = Quaternion(-0.620367, -0.387279, -0.538969, 0.417937)
bones/4/rotation = Quaternion(-0.514121, -0.485468, -0.485468, 0.514122)
bones/4/scale = Vector3(0.999999, 0.999999, 1)
bones/5/name = "lowerarm.l"
bones/5/parent = 4
bones/5/rest = Transform3D(0.993887, 0.110402, -1.19007e-07, -0.110402, 0.993887, 3.28831e-09, 1.18643e-07, 9.87044e-09, 1, -3.21966e-09, 0.241897, -1.19406e-07)
bones/5/enabled = true
bones/5/position = Vector3(-3.21966e-09, 0.241897, -1.19406e-07)
bones/5/rotation = Quaternion(2.08978e-08, -4.73488e-08, -0.581822, 0.813316)
bones/5/rotation = Quaternion(1.64805e-09, -5.95036e-08, -0.0552856, 0.998471)
bones/5/scale = Vector3(1, 1, 1)
bones/6/name = "wrist.l"
bones/6/parent = 5
bones/6/rest = Transform3D(0.998579, -0.0532972, -6.01854e-10, 0.0532972, 0.998579, 1.78776e-10, 5.9147e-10, -2.10599e-10, 1, 8.71929e-09, 0.260044, -1.50195e-10)
bones/6/enabled = true
bones/6/position = Vector3(8.71929e-09, 0.260044, -1.50195e-10)
bones/6/rotation = Quaternion(-9.73784e-11, -2.98437e-10, 0.0266581, 0.999645)
bones/6/rotation = Quaternion(-9.73783e-11, -2.98437e-10, 0.0266581, 0.999645)
bones/6/scale = Vector3(1, 1, 1)
bones/7/name = "hand.l"
bones/7/parent = 6
bones/7/rest = Transform3D(1, 1.09104e-05, 2.66204e-07, -1.09104e-05, 1, -2.40181e-09, -2.66204e-07, 2.39891e-09, 1, 9.08162e-13, 0.0738258, 2.22045e-16)
bones/7/enabled = true
bones/7/position = Vector3(9.08162e-13, 0.0738258, 2.22045e-16)
bones/7/rotation = Quaternion(-0.228915, -0.524509, -0.0801326, 0.816129)
bones/7/rotation = Quaternion(1.20018e-09, 1.33102e-07, -5.4552e-06, 1)
bones/7/scale = Vector3(1, 1, 1)
bones/8/name = "handslot.l"
bones/8/parent = 7
@ -70099,28 +70063,28 @@ bones/9/parent = 3
bones/9/rest = Transform3D(0.0572842, -0.998357, 5.06639e-07, 5.66244e-07, 4.76837e-07, 1, -0.998357, -0.0572843, 4.76837e-07, -0.212007, 0.134132, 8.40246e-08)
bones/9/enabled = true
bones/9/position = Vector3(-0.212007, 0.134132, 8.40246e-08)
bones/9/rotation = Quaternion(-0.710022, -0.0978999, 0.298202, 0.630365)
bones/9/rotation = Quaternion(-0.514121, 0.485468, 0.485468, 0.514122)
bones/9/scale = Vector3(0.999999, 0.999999, 1)
bones/10/name = "lowerarm.r"
bones/10/parent = 9
bones/10/rest = Transform3D(0.993887, -0.110402, 1.19007e-07, 0.110402, 0.993887, 3.28831e-09, -1.18643e-07, 9.87044e-09, 1, -7.12186e-11, 0.241897, -1.19406e-07)
bones/10/enabled = true
bones/10/position = Vector3(-7.12186e-11, 0.241897, -1.19406e-07)
bones/10/rotation = Quaternion(3.4276e-08, 7.52896e-08, 0.682071, 0.731286)
bones/10/rotation = Quaternion(1.64805e-09, 5.95036e-08, 0.0552856, 0.998471)
bones/10/scale = Vector3(1, 1, 1)
bones/11/name = "wrist.r"
bones/11/parent = 10
bones/11/rest = Transform3D(0.998579, 0.0532972, 6.01854e-10, -0.0532972, 0.998579, 1.78776e-10, -5.9147e-10, -2.10599e-10, 1, -8.71838e-09, 0.260044, -1.50195e-10)
bones/11/enabled = true
bones/11/position = Vector3(-8.71838e-09, 0.260044, -1.50195e-10)
bones/11/rotation = Quaternion(-9.73784e-11, 2.98437e-10, -0.0266581, 0.999645)
bones/11/rotation = Quaternion(-9.73783e-11, 2.98437e-10, -0.0266581, 0.999645)
bones/11/scale = Vector3(1, 1, 1)
bones/12/name = "hand.r"
bones/12/parent = 11
bones/12/rest = Transform3D(1, -1.09104e-05, -1.78637e-07, 1.09104e-05, 1, -2.40084e-09, 1.78637e-07, 2.39889e-09, 1, 1.33227e-15, 0.0738258, 2.22045e-16)
bones/12/enabled = true
bones/12/position = Vector3(1.33227e-15, 0.0738258, 2.22045e-16)
bones/12/rotation = Quaternion(-0.464659, 0.10288, 0.0471321, 0.878229)
bones/12/rotation = Quaternion(1.19993e-09, -8.93185e-08, 5.4552e-06, 1)
bones/12/scale = Vector3(1, 1, 1)
bones/13/name = "handslot.r"
bones/13/parent = 12
@ -70140,92 +70104,92 @@ bones/15/name = "upperleg.l"
bones/15/parent = 1
bones/15/rest = Transform3D(1, -1.42215e-07, -2.65602e-08, -1.43052e-07, -0.999396, -0.0347412, -2.16035e-08, 0.0347411, -0.999398, 0.170945, 0.113587, 1.39233e-08)
bones/15/enabled = true
bones/15/position = Vector3(0.170945, 0.0841763, -0.0192146)
bones/15/rotation = Quaternion(0.999883, -3.40886e-07, -9.97875e-08, 0.0153211)
bones/15/position = Vector3(0.170945, 0.113587, 1.39233e-08)
bones/15/rotation = Quaternion(0.999849, -7.13275e-08, -1.20428e-08, 0.0173732)
bones/15/scale = Vector3(1, 1, 1)
bones/16/name = "lowerleg.l"
bones/16/parent = 15
bones/16/rest = Transform3D(1, 1.6129e-07, 1.20856e-07, -1.3212e-07, 0.977433, -0.211248, -1.52201e-07, 0.211248, 0.977433, 3.57982e-09, 0.227077, -6.13986e-09)
bones/16/enabled = true
bones/16/position = Vector3(3.57982e-09, 0.227077, -6.13986e-09)
bones/16/rotation = Quaternion(0.826102, 3.89074e-08, -5.73701e-07, 0.563521)
bones/16/rotation = Quaternion(0.106225, 6.86527e-08, -7.377e-08, 0.994342)
bones/16/scale = Vector3(1, 1, 1)
bones/17/name = "foot.l"
bones/17/parent = 16
bones/17/rest = Transform3D(1, 4.64335e-08, 6.01239e-08, -7.59277e-08, 0.585515, 0.810661, 2.4383e-09, -0.810662, 0.585514, 1.83222e-10, 0.149437, 9.66537e-10)
bones/17/enabled = true
bones/17/position = Vector3(1.83222e-10, 0.149437, 9.66537e-10)
bones/17/rotation = Quaternion(-0.731463, -1.60072e-07, 2.84109e-07, 0.681881)
bones/17/rotation = Quaternion(-0.455239, 1.61971e-08, -3.43569e-08, 0.890369)
bones/17/scale = Vector3(1, 1, 0.999999)
bones/18/name = "toes.l"
bones/18/parent = 17
bones/18/rest = Transform3D(-1, 1.3329e-07, 6.94339e-08, 4.25341e-08, 0.694104, -0.719875, -1.44146e-07, -0.71987, -0.694109, -1.51142e-08, 0.16565, 5.17173e-09)
bones/18/enabled = true
bones/18/position = Vector3(-1.51142e-08, 0.16565, 5.17173e-09)
bones/18/rotation = Quaternion(2.46844e-08, 0.919821, -0.392339, 6.20159e-08)
bones/18/rotation = Quaternion(4.77598e-08, 0.920355, -0.391084, 5.80155e-08)
bones/18/scale = Vector3(1, 0.999997, 1)
bones/19/name = "upperleg.r"
bones/19/parent = 1
bones/19/rest = Transform3D(1, 1.49611e-07, -6.08626e-08, 1.47406e-07, -0.999396, -0.0347412, -6.60234e-08, 0.0347411, -0.999398, -0.170945, 0.113587, 1.39233e-08)
bones/19/enabled = true
bones/19/position = Vector3(-0.170945, 0.112998, 0.0192146)
bones/19/rotation = Quaternion(0.940714, 2.15689e-07, -3.06969e-08, 0.3392)
bones/19/position = Vector3(-0.170945, 0.113587, 1.39233e-08)
bones/19/rotation = Quaternion(0.999849, 7.42654e-08, -3.17263e-08, 0.0173732)
bones/19/scale = Vector3(1, 1, 1)
bones/20/name = "lowerleg.r"
bones/20/parent = 19
bones/20/rest = Transform3D(1, -1.6129e-07, -1.20856e-07, 1.3212e-07, 0.977433, -0.211248, 1.52201e-07, 0.211248, 0.977433, -3.57982e-09, 0.227077, -6.13986e-09)
bones/20/enabled = true
bones/20/position = Vector3(-3.57982e-09, 0.227077, -6.13986e-09)
bones/20/rotation = Quaternion(0.502659, -5.9687e-08, 3.4908e-07, 0.864485)
bones/20/rotation = Quaternion(0.106225, -6.86527e-08, 7.377e-08, 0.994342)
bones/20/scale = Vector3(1, 1, 1)
bones/21/name = "foot.r"
bones/21/parent = 20
bones/21/rest = Transform3D(1, -1.55132e-07, 2.93521e-07, -1.47115e-07, 0.585515, 0.810661, -2.97621e-07, -0.810662, 0.585514, -1.83221e-10, 0.149437, 9.66542e-10)
bones/21/enabled = true
bones/21/position = Vector3(-1.83221e-10, 0.149437, 9.66542e-10)
bones/21/rotation = Quaternion(-0.688363, 2.12746e-07, -1.69868e-07, 0.725367)
bones/21/rotation = Quaternion(-0.455239, 1.65983e-07, 2.25101e-09, 0.890369)
bones/21/scale = Vector3(1, 1, 0.999999)
bones/22/name = "toes.r"
bones/22/parent = 21
bones/22/rest = Transform3D(-1, 8.95136e-08, 1.0214e-07, -1.1395e-08, 0.694104, -0.719875, -1.35334e-07, -0.71987, -0.694109, 2.13058e-10, 0.16565, 5.17174e-09)
bones/22/enabled = true
bones/22/position = Vector3(2.13058e-10, 0.16565, 5.17174e-09)
bones/22/rotation = Quaternion(2.85558e-08, 0.920066, -0.391763, 6.72221e-08)
bones/22/rotation = Quaternion(2.12198e-08, 0.920355, -0.391084, 6.45059e-08)
bones/22/scale = Vector3(1, 0.999997, 1)
bones/23/name = "kneeIK.l"
bones/23/parent = 0
bones/23/rest = Transform3D(1, -2.59151e-07, -3.89414e-07, -3.89414e-07, 0, -1, 2.59151e-07, 1, 0, 0.170945, 0.29231, 0.575812)
bones/23/enabled = true
bones/23/position = Vector3(0.170945, 0.29231, 0.575812)
bones/23/rotation = Quaternion(0.707107, -2.29302e-07, -4.60552e-08, 0.707107)
bones/23/rotation = Quaternion(0.707107, -2.29302e-07, -4.60549e-08, 0.707107)
bones/23/scale = Vector3(1, 1, 1)
bones/24/name = "control-toe-roll.l"
bones/24/parent = 0
bones/24/rest = Transform3D(1, 1.99485e-07, -2.13163e-14, 2.13163e-14, 0, 1, 1.99485e-07, -1, 0, 0.170945, 0.0259903, 0.245789)
bones/24/enabled = true
bones/24/position = Vector3(0.170945, -0.0297811, -0.120857)
bones/24/rotation = Quaternion(-0.262808, -9.3898e-08, -2.85513e-08, 0.964848)
bones/24/position = Vector3(0.170945, 0.0259903, 0.245789)
bones/24/rotation = Quaternion(-0.707107, -7.05286e-08, -7.05286e-08, 0.707107)
bones/24/scale = Vector3(1, 1, 1)
bones/25/name = "control-heel-roll.l"
bones/25/parent = 24
bones/25/rest = Transform3D(-1, 4.66e-34, 1.42109e-14, -4.69932e-34, -1, -2.76642e-22, 1.42109e-14, -2.76642e-22, 1, 1.94581e-08, 0.362833, -2.42861e-15)
bones/25/enabled = true
bones/25/position = Vector3(1.82801e-08, 0.362833, -6.86159e-09)
bones/25/rotation = Quaternion(7.10544e-15, -1.38321e-22, 1, -2.33983e-34)
bones/25/position = Vector3(1.94581e-08, 0.362833, -2.42861e-15)
bones/25/rotation = Quaternion(7.10545e-15, -1.38321e-22, 1, -2.33983e-34)
bones/25/scale = Vector3(1, 1, 1)
bones/26/name = "control-foot-roll.l"
bones/26/parent = 25
bones/26/rest = Transform3D(-1, -2.70242e-08, -2.14593e-07, -1.35722e-07, -0.694106, 0.719873, -1.68404e-07, 0.719873, 0.694106, -1.11482e-08, 0.213436, -2.50942e-15)
bones/26/enabled = true
bones/26/position = Vector3(-1.11482e-08, 0.213436, -2.50942e-15)
bones/26/rotation = Quaternion(-1.04035e-07, 0.391084, 0.920355, -2.9526e-08)
bones/26/rotation = Quaternion(-1.04035e-07, 0.391084, 0.920355, -2.95261e-08)
bones/26/scale = Vector3(1, 1, 1)
bones/27/name = "heelIK.l"
bones/27/parent = 26
bones/27/rest = Transform3D(1, 1.74656e-07, -7.54001e-08, -6.69512e-08, 0.694106, 0.719873, 1.78066e-07, -0.719873, 0.694106, 8.58988e-09, 0.16565, -5.09137e-09)
bones/27/enabled = true
bones/27/position = Vector3(8.58988e-09, 0.16565, -5.09137e-09)
bones/27/rotation = Quaternion(-0.391084, -6.885e-08, -6.56288e-08, 0.920355)
bones/27/rotation = Quaternion(-0.391084, -6.88502e-08, -6.56289e-08, 0.920355)
bones/27/scale = Vector3(1, 1, 1)
bones/28/name = "IK-foot.l"
bones/28/parent = 26
@ -70239,28 +70203,28 @@ bones/29/parent = 25
bones/29/rest = Transform3D(1, 3.89339e-08, -1.3482e-16, -3.89339e-08, 1, -2.71393e-22, 1.3482e-16, 2.76642e-22, 1, -4.55695e-09, -7.95029e-10, -1.86265e-09)
bones/29/enabled = true
bones/29/position = Vector3(-4.55695e-09, -7.95029e-10, -1.86265e-09)
bones/29/rotation = Quaternion(1.37009e-22, -6.74098e-17, -1.94669e-08, 1)
bones/29/rotation = Quaternion(1.37009e-22, -6.741e-17, -1.9467e-08, 1)
bones/29/scale = Vector3(1, 1, 1)
bones/30/name = "kneeIK.r"
bones/30/parent = 0
bones/30/rest = Transform3D(1, -2.59151e-07, 1.50996e-07, 1.50996e-07, 0, -1, 2.59151e-07, 1, 0, -0.170945, 0.29231, 0.575812)
bones/30/enabled = true
bones/30/position = Vector3(-0.170945, 0.29231, 0.575812)
bones/30/rotation = Quaternion(0.707107, -3.82385e-08, 1.45009e-07, 0.707107)
bones/30/rotation = Quaternion(0.707107, -3.82386e-08, 1.45009e-07, 0.707107)
bones/30/scale = Vector3(1, 1, 1)
bones/31/name = "control-toe-roll.r"
bones/31/parent = 0
bones/31/rest = Transform3D(1, 1.99485e-07, -7.10543e-15, 7.10543e-15, 0, 1, 1.99485e-07, -1, 0, -0.170945, 0.0259903, 0.245789)
bones/31/enabled = true
bones/31/position = Vector3(-0.170945, 0.137674, 0.400664)
bones/31/rotation = Quaternion(-0.831099, -5.7117e-08, -8.1248e-08, 0.556125)
bones/31/position = Vector3(-0.170945, 0.0259903, 0.245789)
bones/31/rotation = Quaternion(-0.707107, -7.05286e-08, -7.05286e-08, 0.707107)
bones/31/scale = Vector3(1, 1, 1)
bones/32/name = "control-heel-roll.r"
bones/32/parent = 31
bones/32/rest = Transform3D(-1, 4.66e-34, 1.42109e-14, -4.69932e-34, -1, -2.76642e-22, 1.42109e-14, -2.76642e-22, 1, 1.94581e-08, 0.362833, 2.42861e-15)
bones/32/enabled = true
bones/32/position = Vector3(1.94581e-08, 0.362833, -2.09087e-09)
bones/32/rotation = Quaternion(7.10544e-15, -1.38321e-22, 1, -2.33983e-34)
bones/32/position = Vector3(1.94581e-08, 0.362833, 2.42861e-15)
bones/32/rotation = Quaternion(7.10545e-15, -1.38321e-22, 1, -2.33983e-34)
bones/32/scale = Vector3(1, 1, 1)
bones/33/name = "control-foot-roll.r"
bones/33/parent = 32
@ -70274,49 +70238,49 @@ bones/34/parent = 33
bones/34/rest = Transform3D(1, 1.74656e-07, -7.54001e-08, -6.69512e-08, 0.694106, 0.719873, 1.78066e-07, -0.719873, 0.694106, -6.31128e-09, 0.16565, 1.36608e-09)
bones/34/enabled = true
bones/34/position = Vector3(-6.31128e-09, 0.16565, 1.36608e-09)
bones/34/rotation = Quaternion(-0.391084, -6.885e-08, -6.56288e-08, 0.920355)
bones/34/rotation = Quaternion(-0.391084, -6.88502e-08, -6.56289e-08, 0.920355)
bones/34/scale = Vector3(1, 1, 1)
bones/35/name = "IK-foot.r"
bones/35/parent = 33
bones/35/rest = Transform3D(1, 8.88173e-16, 3.89414e-07, 8.88173e-16, -1, -1.21054e-21, 3.89414e-07, 1.55641e-21, -1, -2.12124e-08, 0.16565, 1.36608e-09)
bones/35/enabled = true
bones/35/position = Vector3(-2.12124e-08, 0.16565, 1.36608e-09)
bones/35/rotation = Quaternion(1, 4.44086e-16, 1.94707e-07, 6.91739e-22)
bones/35/rotation = Quaternion(1, 4.44087e-16, 1.94707e-07, 6.91738e-22)
bones/35/scale = Vector3(1, 1, 1)
bones/36/name = "IK-toe.r"
bones/36/parent = 32
bones/36/rest = Transform3D(1, 3.89338e-08, -1.3482e-16, -3.89338e-08, 1, -2.71392e-22, 1.3482e-16, 2.76642e-22, 1, -4.55695e-09, 7.95036e-10, -1.86265e-09)
bones/36/enabled = true
bones/36/position = Vector3(-4.55695e-09, 7.95036e-10, -1.86265e-09)
bones/36/rotation = Quaternion(1.37009e-22, -6.74099e-17, -1.94669e-08, 1)
bones/36/rotation = Quaternion(1.37009e-22, -6.741e-17, -1.94669e-08, 1)
bones/36/scale = Vector3(1, 1, 1)
bones/37/name = "elbowIK.l"
bones/37/parent = 0
bones/37/rest = Transform3D(1, 2.05896e-07, -2.84217e-14, 2.84217e-14, 0, 1, 2.05896e-07, -1, 0, 0.453507, 1.10676, -0.588859)
bones/37/enabled = true
bones/37/position = Vector3(0.453508, 0.88116, -0.883876)
bones/37/rotation = Quaternion(-0.707107, -7.27951e-08, -7.27951e-08, 0.707107)
bones/37/position = Vector3(0.453507, 1.10676, -0.588859)
bones/37/rotation = Quaternion(-0.707107, -7.27952e-08, -7.27952e-08, 0.707107)
bones/37/scale = Vector3(1, 1, 1)
bones/38/name = "handIK.l"
bones/38/parent = 0
bones/38/rest = Transform3D(-2.38419e-07, 1, -5.96046e-08, -5.96046e-08, 0, 1, 1, 1.78814e-07, 0, 0.713181, 1.10676, 2.54914e-07)
bones/38/enabled = true
bones/38/position = Vector3(0.513182, 0.940539, 0.211298)
bones/38/rotation = Quaternion(0.55615, 0.436688, 0.55615, 0.436688)
bones/38/position = Vector3(0.713181, 1.10676, 2.54914e-07)
bones/38/rotation = Quaternion(0.5, 0.5, 0.5, -0.5)
bones/38/scale = Vector3(1, 1, 1)
bones/39/name = "elbowIK.r"
bones/39/parent = 0
bones/39/rest = Transform3D(1, 2.05896e-07, -2.84217e-14, 2.84217e-14, 0, 1, 2.05896e-07, -1, 0, -0.453507, 1.10676, -0.58886)
bones/39/enabled = true
bones/39/position = Vector3(-0.453507, 0.88116, -0.883876)
bones/39/rotation = Quaternion(-0.707107, -7.27951e-08, -7.27951e-08, 0.707107)
bones/39/position = Vector3(-0.453507, 1.10676, -0.58886)
bones/39/rotation = Quaternion(-0.707107, -7.27952e-08, -7.27952e-08, 0.707107)
bones/39/scale = Vector3(1, 1, 1)
bones/40/name = "handIK.r"
bones/40/parent = 0
bones/40/rest = Transform3D(1.19209e-07, -1, -5.96046e-08, 5.96046e-08, -1.19209e-07, 1, -1, -1.78814e-07, 0, -0.713182, 1.10676, -8.51573e-08)
bones/40/enabled = true
bones/40/position = Vector3(-0.513182, 0.865513, -0.170083)
bones/40/rotation = Quaternion(-0.698958, 0.107039, 0.698958, -0.107039)
bones/40/position = Vector3(-0.713182, 1.10676, -8.51573e-08)
bones/40/rotation = Quaternion(-0.5, 0.5, 0.5, 0.5)
bones/40/scale = Vector3(1, 1, 1)
[node name="Skeleton_Minion_ArmLeft" type="MeshInstance3D" parent="Skeleton_Minion/Rig/Skeleton3D"]

@ -4,11 +4,14 @@ namespace DRPGActionGame.Player.States;
public partial class AttackState : State
{
private Player2 player;
public override void _Ready() {
player = GetParent<Player2>();
player.Playback.Travel("attack");
}
public override void _PhysicsProcess(double delta) {
}
public override void Exit() {
GD.Print("Exit Attack State");
}
}

@ -10,18 +10,6 @@ public partial class IdleState : State {
}
public override void _PhysicsProcess(double delta) {
Vector3 velocity = player.Velocity;
if (Input.IsActionPressed("WalkRight") || Input.IsActionPressed("WalkLeft") || Input.IsActionPressed("WalkUp") || Input.IsActionPressed("WalkDown"))
player.ChangeState("move");
velocity.X = Mathf.MoveToward(player.Velocity.X, 0, Player2.SPEED);
velocity.Z = Mathf.MoveToward(player.Velocity.Z, 0, Player2.SPEED);
player.Velocity = velocity;
}
public override void Exit() {
GD.Print("Exit Idle State");
}
}

@ -4,11 +4,18 @@ namespace DRPGActionGame.Player.States;
public partial class JumpState : State
{
private Player2 player;
public override void _Ready() {
player = GetParent<Player2>();
player.Playback.Travel("jump");
}
public override void _PhysicsProcess(double delta) {
Vector3 velocity = player.Velocity;
}
if (velocity == Vector3.Zero) player.ChangeState(StateFactory.States.Idle);
public override void Exit() {
GD.Print("Exit Jump State");
player.Velocity = velocity;
}
}

@ -4,6 +4,7 @@ namespace DRPGActionGame.Player.States;
public partial class MoveState : State {
private Player2 player;
public override void _Ready() {
player = GetParent<Player2>();
player.Playback.Travel("move");
@ -11,21 +12,12 @@ public partial class MoveState : State {
public override void _PhysicsProcess(double delta) {
Vector3 velocity = player.Velocity;
if (player.Direction != Vector3.Zero)
{
player.ChangeState("move");
velocity.X = player.Direction.X * Player2.SPEED;
velocity.Z = player.Direction.Z * Player2.SPEED;
}
else {
player.ChangeState("idle");
}
velocity.X = player.Direction.X * Player2.SPEED;
velocity.Z = player.Direction.Z * Player2.SPEED;
if (velocity == Vector3.Zero) player.ChangeState(StateFactory.States.Idle);
player.Velocity = velocity;
}
public override void Exit() {
GD.Print("Exit Move State");
}
}

@ -2,16 +2,17 @@ using Godot;
namespace DRPGActionGame.Player.States;
public abstract partial class State : Node2D {
private string changeState;
public abstract partial class State : Node2D {
public StateFactory.States ChangeState;
private AnimationNodeStateMachinePlayback animation;
private Player2 persistantState;
public abstract void Exit();
public void Exit() => QueueFree();
public void Setup(string cS, AnimationNodeStateMachinePlayback a, Player2 pS) {
changeState = cS;
public void Setup(StateFactory.States cS, AnimationNodeStateMachinePlayback a, Player2 pS) {
Name = cS.ToString();
GD.Print($"Current State: {Name}");
ChangeState = cS;
animation = a;
persistantState = pS;
}

@ -5,12 +5,20 @@ using CollectionExtensions = System.Collections.Generic.CollectionExtensions;
namespace DRPGActionGame.Player.States;
public partial class StateFactory : Node {
private Dictionary<string, State> states = new() {
{"idle", new IdleState()},
{"attack", new AttackState()},
{"move", new MoveState()},
{"jump", new JumpState()}
public enum States {
Idle,
Attack,
Move,
Jump
}
private Dictionary<States, State> states = new() {
{States.Idle, new IdleState()},
{States.Attack, new AttackState()},
{States.Move, new MoveState()},
{States.Jump, new JumpState()}
};
public State GetState(string stateName) => CollectionExtensions.GetValueOrDefault(states, stateName);
public State GetState(States state) => CollectionExtensions.GetValueOrDefault(states, state);
}

@ -36,32 +36,32 @@ folder_colors={
WalkLeft={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
WalkRight={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
WalkUp={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
WalkDown={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
Jump={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}