diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 5963319..13b5122 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=33 format=3 uid="uid://bei4nhkf8lwdo"] +[gd_scene load_steps=34 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/base_mode/base_mode.tres" id="3_cresl"] @@ -17,6 +17,7 @@ [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/base_mode/hit.tres" id="11_cresl"] [ext_resource type="PackedScene" uid="uid://0ysqmqphq6mq" path="res://systems/head/head_system.tscn" id="11_rxwoh"] +[ext_resource type="Resource" uid="uid://d2r0ur8k3cuu3" path="res://systems/inputs/base_mode/drop.tres" id="12_34snm"] [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/base_mode/move.tres" id="17_h6vvl"] @@ -49,6 +50,7 @@ aim_released = ExtResource("8_lhb11") aim_canceled = ExtResource("9_5p2qc") jump = ExtResource("10_4u7i3") hit = ExtResource("11_cresl") +drop = ExtResource("12_34snm") [node name="MeshInstance3D" type="MeshInstance3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) @@ -127,7 +129,6 @@ offset_left = 840.0 offset_top = 1.0 offset_right = -2.0 offset_bottom = 1.0 -enabled = false initial_node_to_watch = NodePath("../StateChart") [node name="WeaponRoot" type="Node3D" parent="."] @@ -138,6 +139,7 @@ ThrowForce = 25.0 StraightThrowDuration = 0.07 [node name="CoyoteTime" type="Timer" parent="."] +wait_time = 0.2 [node name="StateChart" type="Node" parent="."] script = ExtResource("25_wv70j") @@ -199,7 +201,7 @@ delay_in_seconds = "0.0" [node name="WeaponThrown" type="Node" parent="StateChart/Root/Actions"] script = ExtResource("27_34snm") -[node name="ToDashing" type="Node" parent="StateChart/Root/Actions/WeaponThrown"] +[node name="OnAim" type="Node" parent="StateChart/Root/Actions/WeaponThrown"] script = ExtResource("28_n7qhm") to = NodePath("../../Dashing") event = &"aim_pressed" @@ -208,22 +210,46 @@ delay_in_seconds = "0.0" [node name="Hanging" type="Node" parent="StateChart/Root/Actions"] script = ExtResource("27_34snm") -[node name="ToWeaponInHand" type="Node" parent="StateChart/Root/Actions/Hanging"] +[node name="OnJump" type="Node" parent="StateChart/Root/Actions/Hanging"] script = ExtResource("28_n7qhm") to = NodePath("../../WeaponInHand") event = &"jump" delay_in_seconds = "0.0" +[node name="OnDrop" type="Node" parent="StateChart/Root/Actions/Hanging"] +script = ExtResource("28_n7qhm") +to = NodePath("../../WeaponInHand") +event = &"drop" +delay_in_seconds = "0.0" + +[node name="OnMantle" type="Node" parent="StateChart/Root/Actions/Hanging"] +script = ExtResource("28_n7qhm") +to = NodePath("../../WeaponInHand") +event = &"mantle" +delay_in_seconds = "0.0" + [node name="Movement" type="Node" parent="StateChart/Root"] script = ExtResource("26_infe6") initial_state = NodePath("Grounded") +[node name="OnMantle" type="Node" parent="StateChart/Root/Movement"] +script = ExtResource("28_n7qhm") +to = NodePath("../Mantling") +event = &"mantle" +delay_in_seconds = "0.0" + +[node name="OnHang" type="Node" parent="StateChart/Root/Movement"] +script = ExtResource("28_n7qhm") +to = NodePath("../Hanging") +event = &"dash_to_planted" +delay_in_seconds = "0.0" + [node name="Grounded" type="Node" parent="StateChart/Root/Movement"] script = ExtResource("27_34snm") [node name="OnJump" type="Node" parent="StateChart/Root/Movement/Grounded"] script = ExtResource("28_n7qhm") -to = NodePath("../../Airborne/DoubleJumpEnabled") +to = NodePath("../../Airborne/Jump") event = &"jump" delay_in_seconds = "0.0" @@ -233,28 +259,43 @@ to = NodePath("../../Airborne/CoyoteEnabled") event = &"start_falling" delay_in_seconds = "0.0" +[node name="Mantling" type="Node" parent="StateChart/Root/Movement"] +script = ExtResource("27_34snm") + +[node name="ToGrounded" type="Node" parent="StateChart/Root/Movement/Mantling"] +script = ExtResource("28_n7qhm") +to = NodePath("../../Grounded") +event = &"to_grounded" +delay_in_seconds = "0.0" + [node name="Hanging" type="Node" parent="StateChart/Root/Movement"] script = ExtResource("27_34snm") [node name="OnJump" type="Node" parent="StateChart/Root/Movement/Hanging"] script = ExtResource("28_n7qhm") -to = NodePath("../../Airborne/DoubleJumpEnabled") +to = NodePath("../../Airborne/Jump") event = &"jump" delay_in_seconds = "0.0" +[node name="OnDrop" type="Node" parent="StateChart/Root/Movement/Hanging"] +script = ExtResource("28_n7qhm") +to = NodePath("../../Airborne/CoyoteEnabled") +event = &"drop" +delay_in_seconds = "0.0" + [node name="WallHugging" type="Node" parent="StateChart/Root/Movement"] script = ExtResource("27_34snm") [node name="OnJump" type="Node" parent="StateChart/Root/Movement/WallHugging"] script = ExtResource("28_n7qhm") -to = NodePath("../../Airborne/DoubleJumpEnabled") +to = NodePath("../../Airborne/Jump") event = &"jump" delay_in_seconds = "0.0" -[node name="OnLeaveWall" type="Node" parent="StateChart/Root/Movement/WallHugging"] +[node name="OnDrop" type="Node" parent="StateChart/Root/Movement/WallHugging"] script = ExtResource("28_n7qhm") to = NodePath("../../Airborne/CoyoteEnabled") -event = &"start_falling" +event = &"drop" delay_in_seconds = "0.0" [node name="Airborne" type="Node" parent="StateChart/Root/Movement"] @@ -272,7 +313,7 @@ script = ExtResource("27_34snm") [node name="OnJump" type="Node" parent="StateChart/Root/Movement/Airborne/CoyoteEnabled"] script = ExtResource("28_n7qhm") -to = NodePath("../../DoubleJumpEnabled") +to = NodePath("../../Jump") event = &"jump" delay_in_seconds = "0.0" @@ -282,21 +323,40 @@ to = NodePath("../../DoubleJumpEnabled") event = &"coyote_expired" delay_in_seconds = "0.0" +[node name="Jump" type="Node" parent="StateChart/Root/Movement/Airborne"] +script = ExtResource("27_34snm") + +[node name="ToDoubleJump" type="Node" parent="StateChart/Root/Movement/Airborne/Jump"] +script = ExtResource("28_n7qhm") +to = NodePath("../../DoubleJumpEnabled") +event = &"to_double_jump" +delay_in_seconds = "0.0" + [node name="DoubleJumpEnabled" type="Node" parent="StateChart/Root/Movement/Airborne"] script = ExtResource("27_34snm") [node name="OnJump" type="Node" parent="StateChart/Root/Movement/Airborne/DoubleJumpEnabled"] script = ExtResource("28_n7qhm") -to = NodePath("../../Falling") +to = NodePath("../../DoubleJump") event = &"jump" delay_in_seconds = "0.0" +[node name="DoubleJump" type="Node" parent="StateChart/Root/Movement/Airborne"] +script = ExtResource("27_34snm") + +[node name="ToFalling" type="Node" parent="StateChart/Root/Movement/Airborne/DoubleJump"] +script = ExtResource("28_n7qhm") +to = NodePath("../../Falling") +event = &"to_falling" +delay_in_seconds = "0.0" + [node name="Falling" type="Node" parent="StateChart/Root/Movement/Airborne"] 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"] +[connection signal="input_drop" from="InputController" to="." method="OnInputDropPressed"] [connection signal="input_hit" from="InputController" to="." method="OnInputHitPressed"] [connection signal="input_jump" from="InputController" to="." method="OnInputJumpPressed"] [connection signal="input_move" from="InputController" to="." method="OnInputMove"] diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index bdc8eae..4a55351 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -40,6 +40,8 @@ public partial class PlayerController : CharacterBody3D private bool _isAiming; private bool _dashCanceled; + private Timer _coyoteTimer; + private StateChart _playerState; // Actions state private StateChartState _weaponInHand; @@ -49,11 +51,14 @@ public partial class PlayerController : CharacterBody3D private StateChartState _actionHanging; // Movement state private StateChartState _grounded; + private StateChartState _mantling; private StateChartState _movHanging; private StateChartState _wallHugging; private StateChartState _airborne; private StateChartState _coyoteEnabled; + private StateChartState _jump; private StateChartState _doubleJumpEnabled; + private StateChartState _doubleJump; private StateChartState _falling; public override void _Ready() @@ -110,12 +115,17 @@ public partial class PlayerController : CharacterBody3D _actionHanging = StateChartState.Of(GetNode("StateChart/Root/Actions/Hanging")); // Movement states _grounded = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded")); + _mantling = StateChartState.Of(GetNode("StateChart/Root/Movement/Mantling")); _movHanging = StateChartState.Of(GetNode("StateChart/Root/Movement/Hanging")); _wallHugging = StateChartState.Of(GetNode("StateChart/Root/Movement/WallHugging")); _airborne = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne")); _coyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/CoyoteEnabled")); + _jump = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Jump")); _doubleJumpEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJumpEnabled")); + _doubleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJump")); _falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling")); + // State timers + _coyoteTimer = GetNode("CoyoteTime"); /////////////////////////// // Initialize components // @@ -130,7 +140,6 @@ public partial class PlayerController : CharacterBody3D FieldOfView.Init(camera); // Movement stuff - // Getting universal setting from GODOT editor to be in sync float gravitySetting = (float)ProjectSettings.GetSetting("physics/3d/default_gravity"); Gravity.Init(gravitySetting); @@ -161,11 +170,114 @@ public partial class PlayerController : CharacterBody3D /////////////////////////// DashSystem.DashEnded += OnDashEnded; + + _weaponInHand.StateProcessing += HandleWeaponInHand; + _aiming.StateProcessing += HandleAiming; + + _grounded.StatePhysicsProcessing += HandleGrounded; + _airborne.StatePhysicsProcessing += HandleAirborne; + _coyoteEnabled.StateEntered += StartCoyoteTime; + _coyoteTimer.Timeout += CoyoteExpired; + _jump.StateEntered += Jump; + _doubleJump.StateEntered += DoubleJump; + _mantling.StateEntered += Mantle; _dashing.StateEntered += OnDashStarted; _weaponThrown.StateEntered += OnWeaponThrown; } + + /////////////////////////// + // Input Management /////// + /////////////////////////// + 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_pressed"); + } + public void OnInputAimReleased() + { + _playerState.SendEvent("aim_released"); + } + public void OnInputAimCanceled() + { + _playerState.SendEvent("aim_canceled"); + DashSystem.CancelDash(); + } + public void OnInputHitPressed() + { + _playerState.SendEvent("hit_pressed"); + } + public void OnInputJumpPressed() + { + if (MoveSystem.CanMantle()) + { + _playerState.SendEvent("mantle"); + return; + } + + _playerState.SendEvent("jump"); + } + public void OnInputDropPressed() + { + _playerState.SendEvent("drop"); + } + + /////////////////////////// + // Stateful logic ///////// + /////////////////////////// + + // Jumping + public void StartCoyoteTime() + { + _coyoteTimer.Start(); + } + public void CoyoteExpired() + { + _playerState.SendEvent("coyote_expired"); + } + public void Jump() + { + _playerState.SendEvent("to_double_jump"); + PerformJump(false); + } + public void DoubleJump() + { + _playerState.SendEvent("to_falling"); + PerformJump(true); + } + private void PerformJump(bool isDoubleJump) + { + bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight(); + bool isPlayerDead = HealthSystem.IsDead(); + if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead) + MoveSystem.Jump(isDoubleJump); + } + + // Mantling + public void Mantle() + { + var optionTween = MoveSystem.Mantle(); + if (optionTween.IsSome(out var tween)) + tween.Finished += MantleFinished; + } + public void MantleFinished() + { + _playerState.SendEvent("to_grounded"); + } + + // Dashing and weapon throwing public void OnDashStarted() { if (WeaponSystem.FlyingState.Active) @@ -180,7 +292,6 @@ public partial class PlayerController : CharacterBody3D _dashDirection = (DashSystem.DashResolve.DashLocation - GlobalPosition).Normalized(); DashSystem.Dash(); } - public void OnDashEnded() { // Regular dash @@ -211,7 +322,6 @@ public partial class PlayerController : CharacterBody3D if (isPlantedOnWall) { - MoveSystem.CanDoubleJump = true; _playerState.SendEvent("dash_to_planted"); return; // In case states aren't exclusives } @@ -219,7 +329,6 @@ public partial class PlayerController : CharacterBody3D // Weapon planted anywhere else _playerState.SendEvent("dash_ended"); } - public void OnWeaponThrown() { RemoveChild(WeaponRoot); @@ -232,91 +341,53 @@ public partial class PlayerController : CharacterBody3D DashSystem.CancelDash(); WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal); } - - public void OnInputMove(Vector3 value) - { - _inputMove = value; - } - public void OnInputRotateY(float value) + // Regular processes + public void HandleWeaponInHand(float delta) { - _inputRotateY = value; + RotateWeaponWithPlayer(); } - - public void OnInputRotateFloorplane(float value) + public void HandleAiming(float delta) { - _inputRotateFloorplane = value; + RotateWeaponWithPlayer(); + DashSystem.PrepareDash(); } - public void OnInputAimPressed() + // Physics processes + public void HandleGrounded(float delta) { - _playerState.SendEvent("aim_pressed"); + if (!isOnFloorCustom()) + _playerState.SendEvent("start_falling"); } - public void OnInputAimReleased() + public void HandleAirborne(float delta) { - _playerState.SendEvent("aim_released"); - } - public void OnInputAimCanceled() - { - _playerState.SendEvent("aim_canceled"); - DashSystem.CancelDash(); + if (isOnFloorCustom()) + _playerState.SendEvent("grounded"); } - public void OnInputHitPressed() + /////////////////////////// + // Stateless logic //////// + /////////////////////////// + private void LookAround() { - _playerState.SendEvent("hit_pressed"); + Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane); + HeadSystem.LookAround(inputLookDir); } - public void OnInputJumpPressed() + private void MoveAround(double delta) { - _playerState.SendEvent("jump"); - bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight(); - bool isPlayerDead = HealthSystem.IsDead(); - - if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead) - MoveSystem.Jump(IsOnFloor()); - } - - public override void _PhysicsProcess(double delta) - { - var isPlayerDead = HealthSystem.IsDead(); - var isHeadTouchingCeiling = IsHeadTouchingCeiling(); - - TweenQueueSystem.ProcessTweens(); - - if (_weaponInHand.Active || _aiming.Active) - WeaponRoot.SetRotation(HeadSystem.Rotation); - if (_aiming.Active) - DashSystem.PrepareDash(); - var moveAroundParams = new MoveSystem.MoveAroundParameters( delta, _inputMove, isOnFloorCustom(), - isPlayerDead, - isHeadTouchingCeiling, + HealthSystem.IsDead(), + IsHeadTouchingCeiling(), _actionHanging.Active); MoveSystem.MoveAround(moveAroundParams); - - Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane); - HeadSystem.LookAround(inputLookDir); - - Bobbing.CameraBobbingParams cameraBobbingParams = new Bobbing.CameraBobbingParams - { - Delta = (float)delta, - IsOnFloorCustom = isOnFloorCustom(), - Velocity = Velocity - }; - Bobbing.PerformCameraBobbing(cameraBobbingParams); + } - FieldOfView.FovParameters fovParams = new FieldOfView.FovParameters - { - IsCrouchingHeight = CapsuleCollider.IsCrouchingHeight(), - Delta = (float)delta, - SprintSpeed = MoveSystem.SprintSpeed, - Velocity = Velocity - }; - FieldOfView.PerformFovAdjustment(fovParams); + private void HandleStairs(float delta) + { StairsSystem.UpStairsCheckParams upStairsCheckParams = new StairsSystem.UpStairsCheckParams { @@ -331,11 +402,6 @@ public partial class PlayerController : CharacterBody3D GlobalTransformFromDriver = GlobalTransform, Rid = GetRid() }; - - // TODO: SnapUpStairsCheck influences the ability of player to crouch because of `stepHeightY <= 0.01` part - // Ideally, it should not. SnapUpStairsCheck and SnapDownStairsCheck should be called, when player is actually - // on the stairs - StairsSystem.UpStairsCheckResult upStairsCheckResult = StairsSystem.SnapUpStairsCheck(upStairsCheckParams); if (upStairsCheckResult.UpdateRequired) @@ -378,6 +444,29 @@ public partial class PlayerController : CharacterBody3D StairsSystem.SlideCameraSmoothBackToOrigin(slideCameraParams); } + private void CameraModifications(float delta) + { + Bobbing.CameraBobbingParams cameraBobbingParams = new Bobbing.CameraBobbingParams + { + Delta = delta, + IsOnFloorCustom = isOnFloorCustom(), + Velocity = Velocity + }; + Bobbing.PerformCameraBobbing(cameraBobbingParams); + + FieldOfView.FovParameters fovParams = new FieldOfView.FovParameters + { + IsCrouchingHeight = CapsuleCollider.IsCrouchingHeight(), + Delta = (float)delta, + SprintSpeed = MoveSystem.SprintSpeed, + Velocity = Velocity + }; + FieldOfView.PerformFovAdjustment(fovParams); + } + + /////////////////////////// + // Helpers //////////////// + /////////////////////////// private bool IsHeadTouchingCeiling() { for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++) @@ -395,4 +484,22 @@ public partial class PlayerController : CharacterBody3D { return IsOnFloor() || StairsSystem.WasSnappedToStairsLastFrame(); } + + public void RotateWeaponWithPlayer() + { + WeaponRoot.SetRotation(HeadSystem.Rotation); + } + + /////////////////////////// + // Processes ////////////// + /////////////////////////// + public override void _PhysicsProcess(double delta) + { + TweenQueueSystem.ProcessTweens(); + + LookAround(); + MoveAround(delta); + CameraModifications((float) delta); + HandleStairs((float) delta); + } } diff --git a/systems/inputs/base_mode/base_mode.tres b/systems/inputs/base_mode/base_mode.tres index c1e947d..cf500ae 100644 --- a/systems/inputs/base_mode/base_mode.tres +++ b/systems/inputs/base_mode/base_mode.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" script_class="GUIDEMappingContext" load_steps=60 format=3 uid="uid://bl5crtu1gkrtr"] +[gd_resource type="Resource" script_class="GUIDEMappingContext" load_steps=65 format=3 uid="uid://bl5crtu1gkrtr"] [ext_resource type="Script" uid="uid://cpplm41b5bt6m" path="res://addons/guide/guide_action_mapping.gd" id="1_qmhk6"] [ext_resource type="Resource" uid="uid://htqvokm8mufq" path="res://systems/inputs/base_mode/move.tres" id="2_g6bbx"] @@ -21,6 +21,7 @@ [ext_resource type="Script" uid="uid://rvttn472ix6v" path="res://addons/guide/inputs/guide_input_joy_button.gd" id="19_qkgmj"] [ext_resource type="Resource" uid="uid://bdit2jy5gbpts" path="res://systems/inputs/base_mode/jump.tres" id="21_818lq"] [ext_resource type="Resource" uid="uid://b5gx3q8nvu72e" path="res://systems/inputs/base_mode/hit.tres" id="22_2hs2y"] +[ext_resource type="Resource" uid="uid://d2r0ur8k3cuu3" path="res://systems/inputs/base_mode/drop.tres" id="22_qmhk6"] [ext_resource type="Script" uid="uid://dsa1dnifd6w32" path="res://addons/guide/guide_mapping_context.gd" id="23_llfhp"] [sub_resource type="Resource" id="Resource_vkvga"] @@ -251,8 +252,33 @@ script = ExtResource("1_qmhk6") action = ExtResource("22_2hs2y") input_mappings = Array[ExtResource("3_yp12v")]([SubResource("Resource_500v3")]) +[sub_resource type="Resource" id="Resource_g6bbx"] +script = ExtResource("19_qkgmj") +button = 1 +joy_index = -1 + +[sub_resource type="Resource" id="Resource_yp12v"] +script = ExtResource("15_fykw6") +actuation_threshold = 0.5 + +[sub_resource type="Resource" id="Resource_1rw8g"] +script = ExtResource("3_yp12v") +override_action_settings = false +is_remappable = false +display_name = "" +display_category = "" +input = SubResource("Resource_g6bbx") +modifiers = Array[ExtResource("5_0qat1")]([]) +triggers = Array[ExtResource("8_2tfaw")]([SubResource("Resource_yp12v")]) + +[sub_resource type="Resource" id="Resource_0qat1"] +script = ExtResource("1_qmhk6") +action = ExtResource("22_qmhk6") +input_mappings = Array[ExtResource("3_yp12v")]([SubResource("Resource_1rw8g")]) +metadata/_guide_input_mappings_collapsed = false + [resource] script = ExtResource("23_llfhp") display_name = "" -mappings = Array[ExtResource("1_qmhk6")]([SubResource("Resource_88x08"), SubResource("Resource_tgr2g"), SubResource("Resource_iarn8"), SubResource("Resource_0hmrk"), SubResource("Resource_iihs4"), SubResource("Resource_0s4kt"), SubResource("Resource_xt1x5"), SubResource("Resource_ew1hw")]) +mappings = Array[ExtResource("1_qmhk6")]([SubResource("Resource_88x08"), SubResource("Resource_tgr2g"), SubResource("Resource_iarn8"), SubResource("Resource_0hmrk"), SubResource("Resource_iihs4"), SubResource("Resource_0s4kt"), SubResource("Resource_xt1x5"), SubResource("Resource_ew1hw"), SubResource("Resource_0qat1")]) metadata/_custom_type_script = "uid://dsa1dnifd6w32" diff --git a/systems/inputs/base_mode/drop.tres b/systems/inputs/base_mode/drop.tres new file mode 100644 index 0000000..10849f3 --- /dev/null +++ b/systems/inputs/base_mode/drop.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="GUIDEAction" load_steps=2 format=3 uid="uid://d2r0ur8k3cuu3"] + +[ext_resource type="Script" uid="uid://cluhc11vixkf1" path="res://addons/guide/guide_action.gd" id="1_3acf8"] + +[resource] +script = ExtResource("1_3acf8") +name = &"" +action_value_type = 0 +block_lower_priority_actions = true +emit_as_godot_actions = false +is_remappable = false +display_name = "" +display_category = "" +metadata/_custom_type_script = "uid://cluhc11vixkf1" diff --git a/systems/inputs/input_system.gd b/systems/inputs/input_system.gd index c49b9f8..5280d34 100644 --- a/systems/inputs/input_system.gd +++ b/systems/inputs/input_system.gd @@ -15,6 +15,7 @@ class_name InputController @export var aim_canceled:GUIDEAction @export var jump:GUIDEAction @export var hit:GUIDEAction +@export var drop:GUIDEAction signal input_move(value: Vector3) signal input_rotate_y(value: float) @@ -25,6 +26,7 @@ signal input_aim_released signal input_aim_canceled signal input_jump signal input_hit +signal input_drop func _ready() -> void: GUIDE.enable_mapping_context(base_mode) @@ -34,6 +36,10 @@ func _ready() -> void: aim_canceled.triggered.connect(on_input_aim_canceled) jump.triggered.connect(on_input_jump) hit.triggered.connect(on_input_hit) + drop.triggered.connect(on_input_drop) + +func on_input_drop(): + input_drop.emit() func on_input_hit(): input_hit.emit() diff --git a/systems/move/MoveSystem.cs b/systems/move/MoveSystem.cs index 554e475..ac461ab 100644 --- a/systems/move/MoveSystem.cs +++ b/systems/move/MoveSystem.cs @@ -1,5 +1,6 @@ using Godot; using Movementtests.player_controller.Scripts; +using RustyOptions; namespace Movementtests.systems; @@ -38,8 +39,6 @@ public partial class MoveSystem : Node3D [Export(PropertyHint.Range, "0,5,0.1,or_greater")] public float DoubleJumpSpeedFactor { get; set; } = 2f; - public bool CanDoubleJump { get; set; } = true; - private float _lastFrameWasOnFloor = -Mathf.Inf; private Gravity _gravity; private CharacterBody3D _parent; @@ -81,12 +80,6 @@ public partial class MoveSystem : Node3D y: _parent.Velocity.Y - (_gravity.CalculateGravityForce() * (float)delta), z: _parent.Velocity.Z); } - - if (isOnFloor) - { - _lastFrameWasOnFloor = Engine.GetPhysicsFrames(); - CanDoubleJump = true; - } // The code below is required to quickly adjust player's position on Y-axis when there's a ceiling on the // trajectory of player's jump and player is standing @@ -174,29 +167,33 @@ public partial class MoveSystem : Node3D } } - public void Jump(bool isOnFloor) + public void Jump(bool isDoubleJump) + { + var jumpForce = isDoubleJump + ? _gravity.CalculateJumpForce() * DoubleJumpSpeedFactor + : _gravity.CalculateJumpForce(); + + _parent.Velocity = new Vector3( + x: _parent.Velocity.X, + y: jumpForce, + z: _parent.Velocity.Z); + } + + public bool CanMantle() + { + var mantleLocationResult = _mantleSystem.FindMantleInFrontOfPlayer(); + return mantleLocationResult.IsSome(out _); + } + + public Option Mantle() { var mantleLocationResult = _mantleSystem.FindMantleInFrontOfPlayer(); if (mantleLocationResult.IsSome(out var mantleLocation)) { var duration = 0.1f * mantleLocation.DistanceTo(_parent.Position); - _tweenQueueSystem.QueueTween(mantleLocation, duration); + var tween = _tweenQueueSystem.TweenToLocation(new TweenQueueSystem.TweenInputs(mantleLocation, duration)); + return tween.Some(); } - else if (isOnFloor) - { - _parent.Velocity = new Vector3( - x: _parent.Velocity.X, - y: _gravity.CalculateJumpForce(), - z: _parent.Velocity.Z); - } - else if (CanDoubleJump) - { - CanDoubleJump = false; - _parent.Velocity = new Vector3( - x: _parent.Velocity.X, - y: _gravity.CalculateJumpForce() * DoubleJumpSpeedFactor, - z: _parent.Velocity.Z); - } - + return Option.None; } } \ No newline at end of file