StateMachine

linux
Sascha 2024-02-08 17:47:29 +07:00
parent 74fabb1b9a
commit bc504f5773
12 changed files with 367 additions and 58 deletions

Binary file not shown.

@ -0,0 +1,34 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://clgvdthd2g4kp"
path="res://.godot/imported/Grass.glb-04ac9d081482063301e14dd2cb1ae1c2.scn"
[deps]
source_file="res://Assets/Grass.glb"
dest_files=["res://.godot/imported/Grass.glb-04ac9d081482063301e14dd2cb1ae1c2.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1

@ -1,46 +1,76 @@
using DRPGActionGame.Player.States;
using Godot;
using static DRPGActionGame.Player.States.State;
namespace DRPGActionGame.Player;
public partial class Player2 : CharacterBody3D
{
private const float SPEED = 5.0f;
public const float SPEED = 5.0f;
private const float JUMP_VELOCITY = 4.5f;
public Vector3 Direction;
// Get the gravity from the project settings to be synced with RigidBody nodes.
private float gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle();
[Export] private AnimationPlayer animationPlayer;
// [Export] private AnimationPlayer animationPlayer;
[Export] private AnimationTree animationTree;
public AnimationNodeStateMachinePlayback Playback;
private StateFactory stateFactory;
private State state;
public override void _Ready() {
stateFactory = new();
Playback = (AnimationNodeStateMachinePlayback)animationTree.Get("parameters/playback");
ChangeState("Idle");
ChangeState("Walk");
}
public override void _PhysicsProcess(double delta)
{
Vector3 velocity = Velocity;
// Add the gravity.
if (!IsOnFloor())
velocity.Y -= gravity * (float)delta;
if (!IsOnFloor()) velocity.Y -= gravity * (float)delta;
// Handle Jump.
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
if (Input.IsActionJustPressed("Jump") && IsOnFloor()) {
velocity.Y = JUMP_VELOCITY;
Playback.Travel("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();
if (direction != Vector3.Zero)
{
animationPlayer.Play("Walking_A");
velocity.X = direction.X * SPEED;
velocity.Z = direction.Z * SPEED;
}
else {
animationPlayer.Play("Idle");
velocity.X = Mathf.MoveToward(Velocity.X, 0, SPEED);
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, SPEED);
}
// 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)
// {
// 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;
Velocity = velocity;
MoveAndSlide();
}
public void ChangeState(string newStateName) {
if (state != null) {
state.Exit();
state.QueueFree();
}
//Add New State
state = new StateFactory().GetState(newStateName);
state.Setup("ChangeState", Playback, this);
state.Name = newStateName;
AddChild(state);
}
}

@ -1,4 +1,4 @@
[gd_scene load_steps=113 format=3 uid="uid://cbn878rbtj1a8"]
[gd_scene load_steps=128 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"]
@ -29602,6 +29602,7 @@ tracks/103/keys = PackedFloat32Array(0, 1, 1, 1, 1)
[sub_resource type="Animation" id="Animation_r5nid"]
resource_name = "Idle"
length = 1.06667
loop_mode = 1
tracks/0/type = "position_3d"
tracks/0/imported = true
tracks/0/enabled = true
@ -66200,6 +66201,7 @@ tracks/103/keys = PackedFloat32Array(0, 1, 1, 1, 1)
[sub_resource type="Animation" id="Animation_33sv3"]
resource_name = "Walking_A"
length = 1.06667
loop_mode = 1
tracks/0/type = "position_3d"
tracks/0/imported = true
tracks/0/enabled = true
@ -69959,9 +69961,70 @@ _data = {
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_a6wip"]
height = 1.7
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("animationPlayer")]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_pr3um"]
animation = &"1H_Melee_Attack_Chop"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_iosyq"]
animation = &"Idle"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_6gdft"]
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/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")]
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("animationTree")]
script = ExtResource("1_1dafw")
animationPlayer = NodePath("Skeleton_Minion/AnimationPlayer")
animationTree = NodePath("AnimationTree")
[node name="Skeleton_Minion" type="Node3D" parent="."]
@ -69979,7 +70042,7 @@ 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.330884, 1.03858e-24)
bones/1/position = Vector3(4.35612e-18, 0.347671, 1.03858e-24)
bones/1/rotation = Quaternion(0, -1.19209e-07, 0, 1)
bones/1/scale = Vector3(1, 1, 1)
bones/2/name = "spine"
@ -69987,28 +70050,28 @@ 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.13552e-10, 8.46327e-09, -0.0355799, 0.999367)
bones/2/rotation = Quaternion(1.13525e-10, -8.46118e-09, 0.0419095, 0.999121)
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.12686e-10, -8.44347e-09, 0.0355799, 0.999367)
bones/3/rotation = Quaternion(1.12659e-10, 8.4414e-09, -0.0419095, 0.999121)
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.713071, 0.0739285, -0.278926, 0.638956)
bones/4/rotation = Quaternion(-0.620367, -0.387279, -0.538969, 0.417937)
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.0891e-08, -5.14231e-08, -0.721729, 0.692176)
bones/5/rotation = Quaternion(2.08978e-08, -4.73488e-08, -0.581822, 0.813316)
bones/5/scale = Vector3(1, 1, 1)
bones/6/name = "wrist.l"
bones/6/parent = 5
@ -70022,7 +70085,7 @@ 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.479228, -0.155596, -0.0284516, 0.86332)
bones/7/rotation = Quaternion(-0.228915, -0.524509, -0.0801326, 0.816129)
bones/7/scale = Vector3(1, 1, 1)
bones/8/name = "handslot.l"
bones/8/parent = 7
@ -70036,14 +70099,14 @@ 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.636493, 0.357096, 0.505192, 0.460586)
bones/9/rotation = Quaternion(-0.710022, -0.0978999, 0.298202, 0.630365)
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(2.49669e-08, 4.14683e-08, 0.636323, 0.771423)
bones/10/rotation = Quaternion(3.4276e-08, 7.52896e-08, 0.682071, 0.731286)
bones/10/scale = Vector3(1, 1, 1)
bones/11/name = "wrist.r"
bones/11/parent = 10
@ -70057,7 +70120,7 @@ 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.248741, 0.530141, 0.044882, 0.80936)
bones/12/rotation = Quaternion(-0.464659, 0.10288, 0.0471321, 0.878229)
bones/12/scale = Vector3(1, 1, 1)
bones/13/name = "handslot.r"
bones/13/parent = 12
@ -70077,57 +70140,57 @@ 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.110819, 0.0163086)
bones/15/rotation = Quaternion(0.960184, -2.38297e-07, -1.52548e-08, 0.279367)
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/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.621385, 5.40959e-08, -4.31532e-07, 0.783505)
bones/16/rotation = Quaternion(0.826102, 3.89074e-08, -5.73701e-07, 0.563521)
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.725137, -1.07092e-07, 1.32256e-07, 0.688605)
bones/17/rotation = Quaternion(-0.731463, -1.60072e-07, 2.84109e-07, 0.681881)
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(8.28263e-09, 0.92008, -0.391731, 7.05696e-08)
bones/18/rotation = Quaternion(2.46844e-08, 0.919821, -0.392339, 6.20159e-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.0863558, -0.0163086)
bones/19/rotation = Quaternion(0.999601, 3.30842e-07, 5.86718e-08, 0.0282481)
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/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.899811, -3.01221e-08, 6.24889e-07, 0.436281)
bones/20/rotation = Quaternion(0.502659, -5.9687e-08, 3.4908e-07, 0.864485)
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.737846, 2.10732e-07, -5.40998e-07, 0.674969)
bones/21/rotation = Quaternion(-0.688363, 2.12746e-07, -1.69868e-07, 0.725367)
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.91307e-08, 0.919999, -0.39192, 6.28209e-08)
bones/22/rotation = Quaternion(2.85558e-08, 0.920066, -0.391763, 6.72221e-08)
bones/22/scale = Vector3(1, 0.999997, 1)
bones/23/name = "kneeIK.l"
bones/23/parent = 0
@ -70140,14 +70203,14 @@ 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.0459608, 0.306797)
bones/24/rotation = Quaternion(-0.735315, -6.59373e-08, -7.50026e-08, 0.677726)
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/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.01449e-08, 0.362833, -2.42861e-15)
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/scale = Vector3(1, 1, 1)
bones/26/name = "control-foot-roll.l"
@ -70189,14 +70252,14 @@ 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.0108101, -0.166749)
bones/31/rotation = Quaternion(-0.140648, -1.01138e-07, -1.16413e-08, 0.99006)
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/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, -6.51926e-09)
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/scale = Vector3(1, 1, 1)
bones/33/name = "control-foot-roll.r"
@ -70238,8 +70301,8 @@ 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.871186, -0.141243)
bones/38/rotation = Quaternion(0.694454, 0.133166, 0.694454, 0.133166)
bones/38/position = Vector3(0.513182, 0.940539, 0.211298)
bones/38/rotation = Quaternion(0.55615, 0.436688, 0.55615, 0.436688)
bones/38/scale = Vector3(1, 1, 1)
bones/39/name = "elbowIK.r"
bones/39/parent = 0
@ -70252,8 +70315,8 @@ 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.934865, 0.182459)
bones/40/rotation = Quaternion(-0.57213, 0.415533, 0.57213, -0.415533)
bones/40/position = Vector3(-0.513182, 0.865513, -0.170083)
bones/40/rotation = Quaternion(-0.698958, 0.107039, 0.698958, -0.107039)
bones/40/scale = Vector3(1, 1, 1)
[node name="Skeleton_Minion_ArmLeft" type="MeshInstance3D" parent="Skeleton_Minion/Rig/Skeleton3D"]
@ -70310,3 +70373,8 @@ springArm3D = NodePath("SpringArm3D")
spring_length = 4.0
[node name="Camera3D" type="Camera3D" parent="CameraController/SpringArm3D"]
[node name="AnimationTree" type="AnimationTree" parent="."]
root_node = NodePath("../Skeleton_Minion")
tree_root = SubResource("AnimationNodeStateMachine_v1jjm")
anim_player = NodePath("../Skeleton_Minion/AnimationPlayer")

@ -0,0 +1,14 @@
using Godot;
namespace DRPGActionGame.Player.States;
public partial class AttackState : State
{
public override void _PhysicsProcess(double delta) {
}
public override void Exit() {
GD.Print("Exit Attack State");
}
}

@ -0,0 +1,27 @@
using Godot;
namespace DRPGActionGame.Player.States;
public partial class IdleState : State {
private Player2 player;
public override void _Ready() {
player = GetParent<Player2>();
player.Playback.Travel("Idle");
}
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("Walk");
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");
}
}

@ -0,0 +1,14 @@
using Godot;
namespace DRPGActionGame.Player.States;
public partial class JumpState : State
{
public override void _PhysicsProcess(double delta) {
}
public override void Exit() {
GD.Print("Exit Jump State");
}
}

@ -0,0 +1,31 @@
using Godot;
namespace DRPGActionGame.Player.States;
public partial class MoveState : State {
private Player2 player;
public override void _Ready() {
player = GetParent<Player2>();
player.Playback.Travel("Walk");
}
public override void _PhysicsProcess(double delta) {
Vector3 velocity = player.Velocity;
if (player.Direction != Vector3.Zero)
{
player.ChangeState("Walking");
velocity.X = player.Direction.X * Player2.SPEED;
velocity.Z = player.Direction.Z * Player2.SPEED;
}
else {
player.ChangeState("Idle");
}
player.Velocity = velocity;
}
public override void Exit() {
GD.Print("Exit Move State");
}
}

@ -0,0 +1,18 @@
using Godot;
namespace DRPGActionGame.Player.States;
public abstract partial class State : Node2D {
private string changeState;
private AnimationNodeStateMachinePlayback animation;
private Player2 persistantState;
public abstract void Exit();
public void Setup(string changeState, AnimationNodeStateMachinePlayback animation, Player2 persistantState) {
this.changeState = changeState;
this.animation = animation;
this.persistantState = persistantState;
}
}

@ -0,0 +1,25 @@
using Godot;
using Godot.Collections;
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()}
};
// private void Init() {
// states = new() {
// {"idle", new IdleState()},
// {"attack", new AttackState()},
// {"move", new MoveState()},
// {"jump", new JumpState()}
// };
// }
public State GetState(string stateName) => CollectionExtensions.GetValueOrDefault(states, stateName);
}

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://dfy2rn0ryl0gw"]
[gd_scene load_steps=8 format=3 uid="uid://dfy2rn0ryl0gw"]
[ext_resource type="PackedScene" uid="uid://cbn878rbtj1a8" path="res://Player/Player2.tscn" id="2_6l1py"]
@ -12,9 +12,22 @@ sky_material = SubResource("ProceduralSkyMaterial_lcthy")
background_mode = 2
sky = SubResource("Sky_sl70d")
tonemap_mode = 2
ssr_enabled = true
ssao_enabled = true
ssil_enabled = true
sdfgi_enabled = true
glow_enabled = true
fog_light_color = Color(0.64243, 0.468412, 0.674277, 1)
volumetric_fog_enabled = true
volumetric_fog_density = 0.025
volumetric_fog_albedo = Color(0.927035, 0.613716, 0.636789, 1)
[sub_resource type="BoxMesh" id="BoxMesh_fdw8w"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_tlh1r"]
albedo_color = Color(0.105676, 0.213448, 0.107403, 1)
emission = Color(0.298105, 0.540396, 0.310407, 1)
[sub_resource type="PlaneMesh" id="PlaneMesh_sigdj"]
material = SubResource("StandardMaterial3D_tlh1r")
[sub_resource type="BoxShape3D" id="BoxShape3D_aivjm"]
size = Vector3(50, 1, 50)
@ -32,11 +45,11 @@ shadow_enabled = true
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floor"]
transform = Transform3D(50, 0, 0, 0, 1, 0, 0, 0, 50, 0, 0, 0)
mesh = SubResource("BoxMesh_fdw8w")
mesh = SubResource("PlaneMesh_sigdj")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Floor"]
shape = SubResource("BoxShape3D_aivjm")
[node name="Player2" parent="." node_paths=PackedStringArray("animationPlayer") instance=ExtResource("2_6l1py")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.55437, 0.835652, -1.61826)
animationPlayer = NodePath("Skeleton_Minion/AnimationPlayer")
[node name="Player2" parent="." node_paths=PackedStringArray("animationTree") instance=ExtResource("2_6l1py")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.554, 0, -1.618)
animationTree = NodePath("AnimationTree")

@ -11,12 +11,14 @@ config_version=5
[application]
config/name="3D RPG Action Game"
config/version="0.1"
run/main_scene="res://World.tscn"
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
config/icon="res://icon.svg"
[display]
window/size/viewport_width=1280
window/size/viewport_height=800
window/stretch/mode="canvas_items"
[dotnet]
@ -30,6 +32,39 @@ folder_colors={
"res://Player/": "green"
}
[input]
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)
]
}
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)
]
}
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)
]
}
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)
]
}
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)
]
}
[rendering]
textures/canvas_textures/default_texture_filter=0