diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 6caf4dd..5c0842e 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -39,6 +39,7 @@ [node name="Player" type="CharacterBody3D"] script = ExtResource("1_poq2x") +TimeScaleAimInAir = 0.15 [node name="InputController" type="Node3D" parent="."] script = ExtResource("16_v31n3") @@ -155,13 +156,22 @@ StraightThrowDuration = 0.05 [node name="CoyoteTime" type="Timer" parent="."] 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")] -offset_left = 840.0 +offset_left = 1530.0 offset_top = 1.0 offset_right = -2.0 offset_bottom = 1.0 -enabled = false initial_node_to_watch = NodePath("../StateChart") [node name="StateChart" type="Node" parent="."] diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index ea76b3e..a4dc00b 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -42,6 +42,12 @@ public partial class PlayerController : CharacterBody3D private bool _dashCanceled; 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; // Actions state @@ -130,6 +136,8 @@ public partial class PlayerController : CharacterBody3D _falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling")); // State timers _coyoteTimer = GetNode("CoyoteTime"); + _timeScaleAimInAirTimer = GetNode("TimeScaleAimInAir"); + _timeAfterDashingTimer = GetNode("TimeAfterDashing"); /////////////////////////// // Initialize components // @@ -178,6 +186,8 @@ public partial class PlayerController : CharacterBody3D _weaponInHand.StateProcessing += HandleWeaponInHand; _aiming.StateProcessing += HandleAiming; + _aiming.StateEntered += OnAimingEntered; + _aiming.StateExited += ResetTimeScale; _grounded.StatePhysicsProcessing += HandleGrounded; _airborne.StatePhysicsProcessing += HandleAirborne; @@ -185,6 +195,7 @@ public partial class PlayerController : CharacterBody3D _coyoteEnabled.StateEntered += StartCoyoteTime; _coyoteTimer.Timeout += CoyoteExpired; + _timeScaleAimInAirTimer.Timeout += ResetTimeScale; _jump.StateEntered += Jump; _jumpFromWall.StateEntered += JumpFromWall; _doubleJump.StateEntered += DoubleJump; @@ -277,10 +288,14 @@ public partial class PlayerController : CharacterBody3D { var effectiveJumpDirection = jumpDirection ?? Vector3.Up; var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized(); + + var actualBoost = 1 + MaxJumpBoostAfterDashing * _timeAfterDashingTimer.TimeLeft; + _timeAfterDashingTimer.Stop(); + bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight(); bool isPlayerDead = HealthSystem.IsDead(); if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead) - MoveSystem.Jump(isDoubleJump, jumpVector); + MoveSystem.Jump(isDoubleJump, jumpVector, (float) actualBoost); } // Mantling @@ -298,6 +313,7 @@ public partial class PlayerController : CharacterBody3D // Dashing and weapon throwing public void OnDashStarted() { + _timeAfterDashingTimer.Start(); if (WeaponSystem.FlyingState.Active) { DashSystem.DashResolve = new DashResolveRecord(false, WeaponSystem.GlobalPosition, Vector3.Zero); @@ -359,6 +375,11 @@ public partial class PlayerController : CharacterBody3D DashSystem.CancelDash(); WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal); } + public void OnAimingEntered() + { + if (!isOnFloorCustom()) + ReduceTimeScaleWhileAiming(); + } // Regular processes public void HandleWeaponInHand(float delta) @@ -369,6 +390,9 @@ public partial class PlayerController : CharacterBody3D { RotateWeaponWithPlayer(); DashSystem.PrepareDash(); + + if (isOnFloorCustom()) + ResetTimeScale(); } // Physics processes @@ -384,7 +408,6 @@ public partial class PlayerController : CharacterBody3D if (WallHugSystem.IsWallHugging() && Velocity.Y < 0) _playerState.SendEvent("wall_hug"); } - public void HandleWallHugging(float delta) { if (!WallHugSystem.IsWallHugging()) @@ -494,6 +517,16 @@ public partial class PlayerController : CharacterBody3D /////////////////////////// // Helpers //////////////// /////////////////////////// + public void ReduceTimeScaleWhileAiming() + { + Engine.SetTimeScale(TimeScaleAimInAir); + _timeScaleAimInAirTimer.Start(); + } + public void ResetTimeScale() + { + Engine.SetTimeScale(1); + } + private bool IsHeadTouchingCeiling() { for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++) diff --git a/project.godot b/project.godot index cfa2bb3..9715145 100644 --- a/project.godot +++ b/project.godot @@ -15,7 +15,7 @@ warnings/check_invalid_track_paths=false [application] 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/icon="res://icon.svg" diff --git a/systems/move/MoveSystem.cs b/systems/move/MoveSystem.cs index 6411578..1d03d1e 100644 --- a/systems/move/MoveSystem.cs +++ b/systems/move/MoveSystem.cs @@ -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 jumpForce = isDoubleJump @@ -186,7 +186,7 @@ public partial class MoveSystem : Node3D : _gravity.CalculateJumpForce(); var currentHorizontalVelocity = new Vector3(_parent.Velocity.X, 0, _parent.Velocity.Z); - var jumpVelocity = jumpForce * effectiveJumpDirection; + var jumpVelocity = jumpForce * effectiveJumpDirection * boost; _parent.Velocity = currentHorizontalVelocity + jumpVelocity; }