From b517404dc4cb063f1854a8e1c594a992e898a42c Mon Sep 17 00:00:00 2001 From: Minimata Date: Thu, 5 Jun 2025 12:19:24 +0200 Subject: [PATCH] gd: mapped dash actions on guide inputs --- main.tscn | 1 + player_controller/PlayerController.tscn | 3 +- player_controller/Scripts/DashSystem.cs | 21 +++++++-- player_controller/Scripts/PlayerController.cs | 44 +++++++++---------- player_controller/Scripts/StairsSystem.cs | 3 +- systems/move/MoveSystem.cs | 14 ++++-- 6 files changed, 54 insertions(+), 32 deletions(-) diff --git a/main.tscn b/main.tscn index 0a47101..55275b8 100644 --- a/main.tscn +++ b/main.tscn @@ -176,3 +176,4 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 30.2019, 12.6118, 13.3006) [node name="DebugLayer" type="CanvasLayer" parent="."] [node name="GuideDebugger" parent="DebugLayer" instance=ExtResource("2_0xm2m")] +visible = false diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 478d081..15cb34e 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -126,10 +126,11 @@ target_position = Vector3(0, 1, 0) script = ExtResource("20_rxwoh") WalkSpeed = 10.0 SprintSpeed = 15.0 +DoubleJumpSpeedFactor = 1.4 [node name="Gravity" type="Node3D" parent="."] script = ExtResource("9_lsueh") -Weight = 10.0 +Weight = 6.5 StartVelocity = 4.0 [node name="TweenQueueSystem" parent="." instance=ExtResource("22_rpwev")] diff --git a/player_controller/Scripts/DashSystem.cs b/player_controller/Scripts/DashSystem.cs index 8e057b6..798768a 100644 --- a/player_controller/Scripts/DashSystem.cs +++ b/player_controller/Scripts/DashSystem.cs @@ -14,15 +14,19 @@ public partial class DashSystem: Node3D private Node3D _head; private ShapeCast3D _dashCast3D; private Camera3D _camera; - private MeshInstance3D _dashTarget; + private TweenQueueSystem _tweenQueueSystem; private MantleSystem _mantleSystem; + private MeshInstance3D _dashTarget; + + private DashResolve _dashResolve; - public void Init(Node3D head, Camera3D camera) + public void Init(Node3D head, Camera3D camera, TweenQueueSystem tweenQueueSystem) { _dashCast3D = GetNode("DashCast3D"); _head = head; _camera = camera; + _tweenQueueSystem = tweenQueueSystem; _mantleSystem = GetNode("MantleSystem"); _mantleSystem.Init(this); @@ -69,11 +73,22 @@ public partial class DashSystem: Node3D _dashTarget.SetVisible(true); _dashTarget.SetGlobalPosition(location); - return new DashResolve(shouldMantle, location, mantleLocation); + _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); + } } } diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index e244766..ab3c60d 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -37,6 +37,7 @@ public partial class PlayerController : CharacterBody3D private float _inputRotateFloorplane = 0.0f; private bool _isAiming = false; + private bool _dashCanceled = false; public void OnInputMove(Vector3 value) { @@ -55,18 +56,21 @@ public partial class PlayerController : CharacterBody3D public void OnInputAimPressed() { - _isAiming = true; - GD.Print("Aim pressed"); + if (_dashCanceled) + return; + + DashSystem.PrepareDash(); } public void OnInputAimReleased() { - _isAiming = false; - GD.Print("Aim released"); + if (!_dashCanceled) + DashSystem.Dash(); + _dashCanceled = false; } public void OnInputAimCanceled() { - _isAiming = false; - GD.Print("Aim canceled"); + _dashCanceled = true; + DashSystem.CancelDash(); } public void OnInputJumpPressed() @@ -144,7 +148,7 @@ public partial class PlayerController : CharacterBody3D StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth); DashSystem = GetNode("DashSystem"); - DashSystem.Init(HeadSystem, camera); + DashSystem.Init(HeadSystem, camera, TweenQueueSystem); HealthSystem = GetNode("HealthSystem"); @@ -166,25 +170,17 @@ public partial class PlayerController : CharacterBody3D { TweenQueueSystem.ProcessTweens(); - if (Input.IsActionPressed("aim_dash")) - { - (_shouldMantle, _dashLocation, _mantleLocation) = DashSystem.PrepareDash(); - } - - if (Input.IsActionJustReleased("aim_dash")) - { - DashSystem.Dash(); - TweenQueueSystem.QueueTween(_dashLocation, 0.1f); - if (_shouldMantle) - { - TweenQueueSystem.QueueTween(_mantleLocation, 0.1f); - } - } - var isPlayerDead = HealthSystem.IsDead(); var isHeadTouchingCeiling = IsHeadTouchingCeiling(); - - MoveSystem.MoveAround(delta, _inputMove, isOnFloorCustom(), isPlayerDead, isHeadTouchingCeiling); + + var moveAroundParams = new MoveSystem.MoveAroundParameters( + delta, + _inputMove, + isOnFloorCustom(), + isPlayerDead, + isHeadTouchingCeiling); + MoveSystem.MoveAround(moveAroundParams); + Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane); HeadSystem.LookAround(inputLookDir); diff --git a/player_controller/Scripts/StairsSystem.cs b/player_controller/Scripts/StairsSystem.cs index 55d5ff4..beff8bf 100644 --- a/player_controller/Scripts/StairsSystem.cs +++ b/player_controller/Scripts/StairsSystem.cs @@ -86,7 +86,8 @@ public partial class StairsSystem: Node3D if (parameters.IsCapsuleHeightLessThanNormal) { motionVelocityMultiplier = 1.55f; // Going to crouch mode - }else if (parameters.CurrentSpeedGreaterThanWalkSpeed) + } + else if (parameters.CurrentSpeedGreaterThanWalkSpeed) { motionVelocityMultiplier = 1.1f; // Sprinting } diff --git a/systems/move/MoveSystem.cs b/systems/move/MoveSystem.cs index 1131d1c..9a05847 100644 --- a/systems/move/MoveSystem.cs +++ b/systems/move/MoveSystem.cs @@ -10,6 +10,14 @@ public partial class MoveSystem : Node3D TweenQueueSystem TweenQueueSystem, HeadSystem HeadSystem, CapsuleCollider CapsuleCollider); + + public record MoveAroundParameters( + double Delta, + Vector3 MovementDirection, + bool IsOnFloor, + bool IsDead, + bool IsHeadTouchingCeiling + ); [Export(PropertyHint.Range, "0,20,0.1,or_greater")] public float WalkSpeed { get; set; } = 5.0f; @@ -48,8 +56,10 @@ public partial class MoveSystem : Node3D _currentSpeed = WalkSpeed; } - public void MoveAround(double delta, Vector3 movementDirection, bool isOnFloor, bool isDead, bool isHeadTouchingCeiling) + public void MoveAround(MoveAroundParameters param) { + var (delta, movementDirection, isOnFloor, isDead, isHeadTouchingCeiling) = param; + var doesCapsuleHaveCrouchingHeight = _capsuleCollider.IsCrouchingHeight(); var doesCapsuleHaveDefaultHeight = _capsuleCollider.IsDefaultHeight(); @@ -77,7 +87,6 @@ public partial class MoveSystem : Node3D y: _parent.Velocity.Y - 2.0f, z: _parent.Velocity.Z); } - if (!isDead) { @@ -152,7 +161,6 @@ public partial class MoveSystem : Node3D if (isDead) { _parent.MoveAndSlide(); - return; } }