gd: mapped dash actions on guide inputs

This commit is contained in:
2025-06-05 12:19:24 +02:00
parent 178553956d
commit b517404dc4
6 changed files with 54 additions and 32 deletions

View File

@ -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

View File

@ -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")]

View File

@ -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<ShapeCast3D>("DashCast3D");
_head = head;
_camera = camera;
_tweenQueueSystem = tweenQueueSystem;
_mantleSystem = GetNode<MantleSystem>("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);
}
}
}

View File

@ -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");
DashSystem.Init(HeadSystem, camera);
DashSystem.Init(HeadSystem, camera, TweenQueueSystem);
HealthSystem = GetNode<HealthSystem>("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);

View File

@ -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
}

View File

@ -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;
}
}