gd,refacto: added state chart addon and namespace cleanup
This commit is contained in:
@ -6,7 +6,7 @@ using Godot;
|
||||
// the value of AdditionalGravityPower owned by the Gravity child of
|
||||
// PlayerController.
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Examples.MovementTestbed;
|
||||
|
||||
public partial class LowGravityArea3D : Area3D
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=29 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||
[gd_scene load_steps=31 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bbbrf5ckydfna" path="res://player_controller/Scripts/PlayerController.cs" id="1_poq2x"]
|
||||
[ext_resource type="Resource" uid="uid://bl5crtu1gkrtr" path="res://systems/inputs/walk_mode/base_mode.tres" id="3_cresl"]
|
||||
@ -13,7 +13,6 @@
|
||||
[ext_resource type="PackedScene" uid="uid://wq1okogkhc5l" path="res://systems/mantle/mantle_system.tscn" id="8_qu4wy"]
|
||||
[ext_resource type="Resource" uid="uid://7wm8ywvujwf" path="res://systems/inputs/walk_mode/aim_cancel.tres" id="9_5p2qc"]
|
||||
[ext_resource type="Script" uid="uid://bt0xv2q8iv1vn" path="res://player_controller/Scripts/Gravity.cs" id="9_lsueh"]
|
||||
[ext_resource type="Script" uid="uid://dwoppk8j5fxeg" path="res://player_controller/Scripts/DashSystem.cs" id="9_qu4wy"]
|
||||
[ext_resource type="Resource" uid="uid://bdit2jy5gbpts" path="res://systems/inputs/walk_mode/jump.tres" id="10_4u7i3"]
|
||||
[ext_resource type="Script" uid="uid://g8idirw62qe0" path="res://player_controller/Scripts/Bobbing.cs" id="10_7wk1w"]
|
||||
[ext_resource type="Resource" uid="uid://b5gx3q8nvu72e" path="res://systems/inputs/walk_mode/hit.tres" id="11_cresl"]
|
||||
@ -21,19 +20,19 @@
|
||||
[ext_resource type="Script" uid="uid://b6k73aj5povgv" path="res://player_controller/Scripts/FieldOfView.cs" id="12_m2mxi"]
|
||||
[ext_resource type="Script" uid="uid://b5nk6ntlps3x0" path="res://systems/inputs/input_system.gd" id="16_v31n3"]
|
||||
[ext_resource type="Resource" uid="uid://htqvokm8mufq" path="res://systems/inputs/walk_mode/move.tres" id="17_h6vvl"]
|
||||
[ext_resource type="PackedScene" uid="uid://cqduhd4opgwvm" path="res://systems/dash/dash_system.tscn" id="18_q5h8a"]
|
||||
[ext_resource type="Script" uid="uid://dyy5njw6pxoh4" path="res://systems/move/MoveSystem.cs" id="20_rxwoh"]
|
||||
[ext_resource type="PackedScene" uid="uid://dbe5f0p6lvqtr" path="res://systems/tween_queue/tween_queue_system.tscn" id="22_rpwev"]
|
||||
[ext_resource type="PackedScene" uid="uid://bcwkugn6v3oy7" path="res://addons/godot_state_charts/utilities/state_chart_debugger.tscn" id="24_q5h8a"]
|
||||
[ext_resource type="Script" uid="uid://couw105c3bde4" path="res://addons/godot_state_charts/state_chart.gd" id="25_wv70j"]
|
||||
[ext_resource type="Script" uid="uid://jk2jm1g6q853" path="res://addons/godot_state_charts/compound_state.gd" id="26_infe6"]
|
||||
[ext_resource type="Script" uid="uid://cytafq8i1y8qm" path="res://addons/godot_state_charts/atomic_state.gd" id="27_34snm"]
|
||||
[ext_resource type="Script" uid="uid://cf1nsco3w0mf6" path="res://addons/godot_state_charts/transition.gd" id="28_n7qhm"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_xc2g5"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_wydro"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_qu4wy"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_qu4wy"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_v31n3"]
|
||||
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
script = ExtResource("1_poq2x")
|
||||
|
||||
@ -81,24 +80,7 @@ target_position = Vector3(0, -0.75, 0)
|
||||
MantleEndLocationDistanceFromWall = 1.0
|
||||
MantleHeightCastStart = 2.0
|
||||
|
||||
[node name="DashSystem" type="Node3D" parent="."]
|
||||
script = ExtResource("9_qu4wy")
|
||||
|
||||
[node name="DashCast3D" type="ShapeCast3D" parent="DashSystem"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.68, 0)
|
||||
shape = SubResource("SphereShape3D_qu4wy")
|
||||
target_position = Vector3(0, 0, -20)
|
||||
max_results = 1
|
||||
collision_mask = 2
|
||||
debug_shape_custom_color = Color(0.911631, 0.11884, 0.656218, 1)
|
||||
|
||||
[node name="DashTarget" type="MeshInstance3D" parent="DashSystem"]
|
||||
mesh = SubResource("SphereMesh_qu4wy")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_v31n3")
|
||||
|
||||
[node name="MantleSystem" parent="DashSystem" instance=ExtResource("8_qu4wy")]
|
||||
MantleEndLocationDistanceFromWall = 1.0
|
||||
MantleHeightCastStart = 2.0
|
||||
[node name="DashSystem" parent="." instance=ExtResource("18_q5h8a")]
|
||||
|
||||
[node name="Bobbing" type="Node3D" parent="."]
|
||||
script = ExtResource("10_7wk1w")
|
||||
@ -137,6 +119,43 @@ StartVelocity = 4.0
|
||||
|
||||
[node name="TweenQueueSystem" parent="." instance=ExtResource("22_rpwev")]
|
||||
|
||||
[node name="StateChartDebugger" parent="." instance=ExtResource("24_q5h8a")]
|
||||
offset_left = 840.0
|
||||
offset_top = 1.0
|
||||
offset_right = -2.0
|
||||
offset_bottom = 1.0
|
||||
initial_node_to_watch = NodePath("../StateChart")
|
||||
|
||||
[node name="StateChart" type="Node" parent="."]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("25_wv70j")
|
||||
metadata/_custom_type_script = "uid://couw105c3bde4"
|
||||
|
||||
[node name="Root" type="Node" parent="StateChart"]
|
||||
script = ExtResource("26_infe6")
|
||||
initial_state = NodePath("WeaponInHand")
|
||||
|
||||
[node name="WeaponInHand" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("27_34snm")
|
||||
|
||||
[node name="ToAiming" type="Node" parent="StateChart/Root/WeaponInHand"]
|
||||
script = ExtResource("28_n7qhm")
|
||||
to = NodePath("../../Aiming")
|
||||
event = &"aim_started"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="Aiming" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("27_34snm")
|
||||
|
||||
[node name="Dashing" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("27_34snm")
|
||||
|
||||
[node name="WeaponThrown" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("27_34snm")
|
||||
|
||||
[node name="WeaponPlanted" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("27_34snm")
|
||||
|
||||
[connection signal="input_aim_canceled" from="InputController" to="." method="OnInputAimCanceled"]
|
||||
[connection signal="input_aim_pressed" from="InputController" to="." method="OnInputAimPressed"]
|
||||
[connection signal="input_aim_released" from="InputController" to="." method="OnInputAimReleased"]
|
||||
|
@ -1,4 +1,4 @@
|
||||
using PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class AnimationPlayer : Godot.AnimationPlayer
|
||||
{
|
||||
@ -6,4 +6,4 @@ public partial class AnimationPlayer : Godot.AnimationPlayer
|
||||
{
|
||||
Play(Constants.PLAYERS_HEAD_ANIMATION_ON_DYING);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class Bobbing: Node3D
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class CapsuleCollider : CollisionShape3D
|
||||
{
|
||||
|
@ -1,94 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
|
||||
public record DashComputation(bool HasHit, Vector3 Location, Vector3 CollisionPoint, Vector3 CollisionNormal);
|
||||
|
||||
public record DashResolve(bool EndWithMantle, Vector3 DashLocation, Vector3 MantleLocation);
|
||||
|
||||
public partial class DashSystem: Node3D
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
|
||||
public float DashSpeed { get; set; } = 0.05f;
|
||||
|
||||
private Node3D _head;
|
||||
private ShapeCast3D _dashCast3D;
|
||||
private Camera3D _camera;
|
||||
private TweenQueueSystem _tweenQueueSystem;
|
||||
|
||||
private MantleSystem _mantleSystem;
|
||||
private MeshInstance3D _dashTarget;
|
||||
|
||||
private DashResolve _dashResolve;
|
||||
|
||||
public void Init(Node3D head, Camera3D camera, TweenQueueSystem tweenQueueSystem)
|
||||
{
|
||||
_dashCast3D = GetNode<ShapeCast3D>("DashCast3D");
|
||||
_head = head;
|
||||
_camera = camera;
|
||||
_tweenQueueSystem = tweenQueueSystem;
|
||||
|
||||
_mantleSystem = GetNode<MantleSystem>("MantleSystem");
|
||||
_mantleSystem.Init(this);
|
||||
|
||||
_dashTarget = GetNode<MeshInstance3D>("DashTarget");
|
||||
_dashTarget.SetVisible(false);
|
||||
}
|
||||
|
||||
private DashComputation ComputeDashLocation()
|
||||
{
|
||||
if (!_dashCast3D.IsColliding())
|
||||
{
|
||||
return new DashComputation(false, _dashCast3D.ToGlobal(_dashCast3D.TargetPosition), Vector3.Zero, Vector3.Zero);
|
||||
}
|
||||
var collisionPoint = _dashCast3D.GetCollisionPoint(0);
|
||||
var collisionNormal = _dashCast3D.GetCollisionNormal(0);
|
||||
var collisionShape = (SphereShape3D) _dashCast3D.GetShape();
|
||||
var centerSphereLocation = collisionPoint + collisionNormal * collisionShape.Radius;
|
||||
return new DashComputation(true, centerSphereLocation, collisionPoint, collisionNormal);
|
||||
}
|
||||
|
||||
public DashResolve PrepareDash()
|
||||
{
|
||||
_dashTarget.SetVisible(false);
|
||||
|
||||
_dashCast3D.SetRotation(new Vector3(
|
||||
_camera.Rotation.X,
|
||||
_head.Rotation.Y,
|
||||
_camera.Rotation.Z));
|
||||
|
||||
var (hasHit, location, collisionPoint, collisionNormal) = ComputeDashLocation();
|
||||
|
||||
var shouldMantle = false;
|
||||
var mantleLocation = Vector3.Zero;
|
||||
if (hasHit && Mathf.Abs(collisionNormal.Y) < 0.01f)
|
||||
{
|
||||
var mantleResult = _mantleSystem.FindMantleLocationAtPoint(collisionPoint, collisionNormal);
|
||||
shouldMantle = mantleResult.IsSome(out mantleLocation);
|
||||
}
|
||||
|
||||
var targetColor = shouldMantle ? new Color(0.2f, 0.2f, 1f) : new Color(1f, 1f, 1f);
|
||||
var targetMaterial = (StandardMaterial3D) _dashTarget.GetSurfaceOverrideMaterial(0);
|
||||
targetMaterial.SetAlbedo(targetColor);
|
||||
_dashTarget.SetVisible(true);
|
||||
_dashTarget.SetGlobalPosition(location);
|
||||
|
||||
_dashResolve = new DashResolve(shouldMantle, location, mantleLocation);
|
||||
return _dashResolve;
|
||||
}
|
||||
|
||||
public void CancelDash()
|
||||
{
|
||||
_dashTarget.SetVisible(false);
|
||||
}
|
||||
|
||||
public void Dash()
|
||||
{
|
||||
_dashTarget.SetVisible(false);
|
||||
_tweenQueueSystem.QueueTween(_dashResolve.DashLocation, 0.1f);
|
||||
if (_dashResolve.EndWithMantle)
|
||||
{
|
||||
_tweenQueueSystem.QueueTween(_dashResolve.MantleLocation, 0.1f);
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
uid://dwoppk8j5fxeg
|
@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class FieldOfView: Node3D
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public class Constants
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class Gravity: Node3D
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class HealthSystem : Node3D
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class Mouse : Node3D
|
||||
{
|
||||
|
@ -1,9 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.JavaScript;
|
||||
using Godot;
|
||||
using RustyOptions;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
using GodotStateCharts;
|
||||
using Movementtests.systems;
|
||||
using Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
@ -20,77 +18,30 @@ public partial class PlayerController : CharacterBody3D
|
||||
public HealthSystem HealthSystem;
|
||||
public MoveSystem MoveSystem;
|
||||
public TweenQueueSystem TweenQueueSystem;
|
||||
public StateChart PlayerState;
|
||||
|
||||
private bool _movementEnabled = true;
|
||||
|
||||
private bool _shouldMantle = false;
|
||||
private bool _shouldMantle;
|
||||
private Vector3 _dashLocation = Vector3.Zero;
|
||||
private Vector3 _mantleLocation = Vector3.Zero;
|
||||
|
||||
private float _lastFrameWasOnFloor = -Mathf.Inf;
|
||||
|
||||
private const int NumOfHeadCollisionDetectors = 4;
|
||||
private const int NUM_OF_HEAD_COLLISION_DETECTORS = 4;
|
||||
private RayCast3D[] _headCollisionDetectors;
|
||||
|
||||
private Vector3 _inputMove = Vector3.Zero;
|
||||
private float _inputRotateY = 0.0f;
|
||||
private float _inputRotateFloorplane = 0.0f;
|
||||
private float _inputRotateY;
|
||||
private float _inputRotateFloorplane;
|
||||
|
||||
private bool _isAiming = false;
|
||||
private bool _dashCanceled = false;
|
||||
|
||||
public void OnInputMove(Vector3 value)
|
||||
{
|
||||
_inputMove = value;
|
||||
}
|
||||
|
||||
public void OnInputRotateY(float value)
|
||||
{
|
||||
_inputRotateY = value;
|
||||
}
|
||||
|
||||
public void OnInputRotateFloorplane(float value)
|
||||
{
|
||||
_inputRotateFloorplane = value;
|
||||
}
|
||||
|
||||
public void OnInputAimPressed()
|
||||
{
|
||||
if (_dashCanceled)
|
||||
return;
|
||||
|
||||
DashSystem.PrepareDash();
|
||||
}
|
||||
public void OnInputAimReleased()
|
||||
{
|
||||
if (!_dashCanceled)
|
||||
DashSystem.Dash();
|
||||
_dashCanceled = false;
|
||||
}
|
||||
public void OnInputAimCanceled()
|
||||
{
|
||||
_dashCanceled = true;
|
||||
DashSystem.CancelDash();
|
||||
}
|
||||
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
GD.Print("OnInputHitPressed");
|
||||
}
|
||||
|
||||
public void OnInputJumpPressed()
|
||||
{
|
||||
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
|
||||
bool isPlayerDead = HealthSystem.IsDead();
|
||||
|
||||
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
|
||||
MoveSystem.Jump(IsOnFloor());
|
||||
}
|
||||
private bool _isAiming;
|
||||
private bool _dashCanceled;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_headCollisionDetectors = new RayCast3D[NumOfHeadCollisionDetectors];
|
||||
for (int i = 0; i < NumOfHeadCollisionDetectors; i++)
|
||||
_headCollisionDetectors = new RayCast3D[NUM_OF_HEAD_COLLISION_DETECTORS];
|
||||
for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++)
|
||||
{
|
||||
_headCollisionDetectors[i] = GetNode<RayCast3D>(
|
||||
"HeadCollisionDetectors/HeadCollisionDetector" + i);
|
||||
@ -99,7 +50,14 @@ public partial class PlayerController : CharacterBody3D
|
||||
HeadSystem = GetNode<HeadSystem>("HeadSystem");
|
||||
HeadSystem.Init();
|
||||
|
||||
// Getting dependencies of the components(In godot we manage this from upwards to downwards not vice versa)
|
||||
// Get the state chart node and wrap it in a StateChart object like so, GetNode doesn't work
|
||||
PlayerState = StateChart.Of(GetNode("%StateChart"));
|
||||
|
||||
// Get the poisoned state node and wrap it in a State object, so we can easily
|
||||
// interact with it from C#.
|
||||
// _poisonedStateChartState = StateChartState.Of(GetNode("%Poisoned"));
|
||||
|
||||
// Getting dependencies of the components (In godot we manage this from upwards to downwards not vice versa)
|
||||
Camera3D camera = GetNode<Camera3D>("HeadSystem/CameraSmooth/Camera3D");
|
||||
Node3D cameraSmooth = GetNode<Node3D>("HeadSystem/CameraSmooth");
|
||||
|
||||
@ -118,7 +76,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
ColorRect blurRect = GetNode<ColorRect>("HeadSystem/CameraSmooth/Camera3D/CLBlur(Layer_2)/BlurRect");
|
||||
|
||||
Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
|
||||
// Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
|
||||
|
||||
// Getting components
|
||||
|
||||
@ -168,6 +126,56 @@ public partial class PlayerController : CharacterBody3D
|
||||
HealthSystem.Init(healthSystemParams);
|
||||
}
|
||||
|
||||
public void OnInputMove(Vector3 value)
|
||||
{
|
||||
_inputMove = value;
|
||||
}
|
||||
|
||||
public void OnInputRotateY(float value)
|
||||
{
|
||||
_inputRotateY = value;
|
||||
}
|
||||
|
||||
public void OnInputRotateFloorplane(float value)
|
||||
{
|
||||
_inputRotateFloorplane = value;
|
||||
}
|
||||
|
||||
public void OnInputAimPressed()
|
||||
{
|
||||
PlayerState.SendEvent("aim_started");
|
||||
|
||||
if (_dashCanceled)
|
||||
return;
|
||||
|
||||
DashSystem.PrepareDash();
|
||||
}
|
||||
public void OnInputAimReleased()
|
||||
{
|
||||
if (!_dashCanceled)
|
||||
DashSystem.Dash();
|
||||
_dashCanceled = false;
|
||||
}
|
||||
public void OnInputAimCanceled()
|
||||
{
|
||||
_dashCanceled = true;
|
||||
DashSystem.CancelDash();
|
||||
}
|
||||
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
GD.Print("OnInputHitPressed");
|
||||
}
|
||||
|
||||
public void OnInputJumpPressed()
|
||||
{
|
||||
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
|
||||
bool isPlayerDead = HealthSystem.IsDead();
|
||||
|
||||
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
|
||||
MoveSystem.Jump(IsOnFloor());
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
TweenQueueSystem.ProcessTweens();
|
||||
@ -265,7 +273,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
private bool IsHeadTouchingCeiling()
|
||||
{
|
||||
for (int i = 0; i < NumOfHeadCollisionDetectors; i++)
|
||||
for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++)
|
||||
{
|
||||
if (_headCollisionDetectors[i].IsColliding())
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class StairsSystem: Node3D
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
namespace Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class Stamina : Node
|
||||
{
|
||||
|
Reference in New Issue
Block a user