gd: added bonus jump height if jumping right after dash, and time scale on aiming in air

This commit is contained in:
2025-06-10 20:24:35 +02:00
parent c50f248c9d
commit cb4c16a3ca
4 changed files with 50 additions and 7 deletions

View File

@ -39,6 +39,7 @@
[node name="Player" type="CharacterBody3D"] [node name="Player" type="CharacterBody3D"]
script = ExtResource("1_poq2x") script = ExtResource("1_poq2x")
TimeScaleAimInAir = 0.15
[node name="InputController" type="Node3D" parent="."] [node name="InputController" type="Node3D" parent="."]
script = ExtResource("16_v31n3") script = ExtResource("16_v31n3")
@ -155,13 +156,22 @@ StraightThrowDuration = 0.05
[node name="CoyoteTime" type="Timer" parent="."] [node name="CoyoteTime" type="Timer" parent="."]
wait_time = 0.2 wait_time = 0.2
one_shot = true
[node name="TimeScaleAimInAir" type="Timer" parent="."]
wait_time = 2.0
one_shot = true
ignore_time_scale = true
[node name="TimeAfterDashing" type="Timer" parent="."]
wait_time = 0.3
one_shot = true
[node name="StateChartDebugger" parent="." instance=ExtResource("24_q5h8a")] [node name="StateChartDebugger" parent="." instance=ExtResource("24_q5h8a")]
offset_left = 840.0 offset_left = 1530.0
offset_top = 1.0 offset_top = 1.0
offset_right = -2.0 offset_right = -2.0
offset_bottom = 1.0 offset_bottom = 1.0
enabled = false
initial_node_to_watch = NodePath("../StateChart") initial_node_to_watch = NodePath("../StateChart")
[node name="StateChart" type="Node" parent="."] [node name="StateChart" type="Node" parent="."]

View File

@ -42,6 +42,12 @@ public partial class PlayerController : CharacterBody3D
private bool _dashCanceled; private bool _dashCanceled;
private Timer _coyoteTimer; private Timer _coyoteTimer;
private Timer _timeScaleAimInAirTimer;
private Timer _timeAfterDashingTimer;
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
public float TimeScaleAimInAir { get; set; } = 0.2f;
[Export(PropertyHint.Range, "1,5,0.1,or_greater")]
public float MaxJumpBoostAfterDashing { get; set; } = 2f;
private StateChart _playerState; private StateChart _playerState;
// Actions state // Actions state
@ -130,6 +136,8 @@ public partial class PlayerController : CharacterBody3D
_falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling")); _falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling"));
// State timers // State timers
_coyoteTimer = GetNode<Timer>("CoyoteTime"); _coyoteTimer = GetNode<Timer>("CoyoteTime");
_timeScaleAimInAirTimer = GetNode<Timer>("TimeScaleAimInAir");
_timeAfterDashingTimer = GetNode<Timer>("TimeAfterDashing");
/////////////////////////// ///////////////////////////
// Initialize components // // Initialize components //
@ -178,6 +186,8 @@ public partial class PlayerController : CharacterBody3D
_weaponInHand.StateProcessing += HandleWeaponInHand; _weaponInHand.StateProcessing += HandleWeaponInHand;
_aiming.StateProcessing += HandleAiming; _aiming.StateProcessing += HandleAiming;
_aiming.StateEntered += OnAimingEntered;
_aiming.StateExited += ResetTimeScale;
_grounded.StatePhysicsProcessing += HandleGrounded; _grounded.StatePhysicsProcessing += HandleGrounded;
_airborne.StatePhysicsProcessing += HandleAirborne; _airborne.StatePhysicsProcessing += HandleAirborne;
@ -185,6 +195,7 @@ public partial class PlayerController : CharacterBody3D
_coyoteEnabled.StateEntered += StartCoyoteTime; _coyoteEnabled.StateEntered += StartCoyoteTime;
_coyoteTimer.Timeout += CoyoteExpired; _coyoteTimer.Timeout += CoyoteExpired;
_timeScaleAimInAirTimer.Timeout += ResetTimeScale;
_jump.StateEntered += Jump; _jump.StateEntered += Jump;
_jumpFromWall.StateEntered += JumpFromWall; _jumpFromWall.StateEntered += JumpFromWall;
_doubleJump.StateEntered += DoubleJump; _doubleJump.StateEntered += DoubleJump;
@ -277,10 +288,14 @@ public partial class PlayerController : CharacterBody3D
{ {
var effectiveJumpDirection = jumpDirection ?? Vector3.Up; var effectiveJumpDirection = jumpDirection ?? Vector3.Up;
var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized(); var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized();
var actualBoost = 1 + MaxJumpBoostAfterDashing * _timeAfterDashingTimer.TimeLeft;
_timeAfterDashingTimer.Stop();
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight(); bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
bool isPlayerDead = HealthSystem.IsDead(); bool isPlayerDead = HealthSystem.IsDead();
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead) if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
MoveSystem.Jump(isDoubleJump, jumpVector); MoveSystem.Jump(isDoubleJump, jumpVector, (float) actualBoost);
} }
// Mantling // Mantling
@ -298,6 +313,7 @@ public partial class PlayerController : CharacterBody3D
// Dashing and weapon throwing // Dashing and weapon throwing
public void OnDashStarted() public void OnDashStarted()
{ {
_timeAfterDashingTimer.Start();
if (WeaponSystem.FlyingState.Active) if (WeaponSystem.FlyingState.Active)
{ {
DashSystem.DashResolve = new DashResolveRecord(false, WeaponSystem.GlobalPosition, Vector3.Zero); DashSystem.DashResolve = new DashResolveRecord(false, WeaponSystem.GlobalPosition, Vector3.Zero);
@ -359,6 +375,11 @@ public partial class PlayerController : CharacterBody3D
DashSystem.CancelDash(); DashSystem.CancelDash();
WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal); WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal);
} }
public void OnAimingEntered()
{
if (!isOnFloorCustom())
ReduceTimeScaleWhileAiming();
}
// Regular processes // Regular processes
public void HandleWeaponInHand(float delta) public void HandleWeaponInHand(float delta)
@ -369,6 +390,9 @@ public partial class PlayerController : CharacterBody3D
{ {
RotateWeaponWithPlayer(); RotateWeaponWithPlayer();
DashSystem.PrepareDash(); DashSystem.PrepareDash();
if (isOnFloorCustom())
ResetTimeScale();
} }
// Physics processes // Physics processes
@ -384,7 +408,6 @@ public partial class PlayerController : CharacterBody3D
if (WallHugSystem.IsWallHugging() && Velocity.Y < 0) if (WallHugSystem.IsWallHugging() && Velocity.Y < 0)
_playerState.SendEvent("wall_hug"); _playerState.SendEvent("wall_hug");
} }
public void HandleWallHugging(float delta) public void HandleWallHugging(float delta)
{ {
if (!WallHugSystem.IsWallHugging()) if (!WallHugSystem.IsWallHugging())
@ -494,6 +517,16 @@ public partial class PlayerController : CharacterBody3D
/////////////////////////// ///////////////////////////
// Helpers //////////////// // Helpers ////////////////
/////////////////////////// ///////////////////////////
public void ReduceTimeScaleWhileAiming()
{
Engine.SetTimeScale(TimeScaleAimInAir);
_timeScaleAimInAirTimer.Start();
}
public void ResetTimeScale()
{
Engine.SetTimeScale(1);
}
private bool IsHeadTouchingCeiling() private bool IsHeadTouchingCeiling()
{ {
for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++) for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++)

View File

@ -15,7 +15,7 @@ warnings/check_invalid_track_paths=false
[application] [application]
config/name="Movement tests" config/name="Movement tests"
run/main_scene="res://menus/scenes/opening/opening_with_logo.tscn" run/main_scene="uid://cxbskue0lj2gv"
config/features=PackedStringArray("4.4", "C#", "Forward Plus") config/features=PackedStringArray("4.4", "C#", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"

View File

@ -178,7 +178,7 @@ public partial class MoveSystem : Node3D
} }
} }
public void Jump(bool isDoubleJump, Vector3? jumpDirection = null) public void Jump(bool isDoubleJump, Vector3? jumpDirection = null, float boost = 1.0f)
{ {
var effectiveJumpDirection = jumpDirection ?? Vector3.Up; var effectiveJumpDirection = jumpDirection ?? Vector3.Up;
var jumpForce = isDoubleJump var jumpForce = isDoubleJump
@ -186,7 +186,7 @@ public partial class MoveSystem : Node3D
: _gravity.CalculateJumpForce(); : _gravity.CalculateJumpForce();
var currentHorizontalVelocity = new Vector3(_parent.Velocity.X, 0, _parent.Velocity.Z); var currentHorizontalVelocity = new Vector3(_parent.Velocity.X, 0, _parent.Velocity.Z);
var jumpVelocity = jumpForce * effectiveJumpDirection; var jumpVelocity = jumpForce * effectiveJumpDirection * boost;
_parent.Velocity = currentHorizontalVelocity + jumpVelocity; _parent.Velocity = currentHorizontalVelocity + jumpVelocity;
} }