From e6cdb26ee0f2fa6b0d21395883137511cc7cf372 Mon Sep 17 00:00:00 2001 From: Minimata Date: Fri, 12 Sep 2025 14:54:08 +0200 Subject: [PATCH] throwing weapon back on --- player_controller/PlayerController.tscn | 24 +- player_controller/Scripts/PlayerController.cs | 289 +++++++----------- systems/dash/DashSystem.cs | 31 -- systems/weapon/WeaponSystem.cs | 2 +- 4 files changed, 129 insertions(+), 217 deletions(-) diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 1f9a903..62df327 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=44 format=3 uid="uid://bei4nhkf8lwdo"] +[gd_scene load_steps=43 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="Curve" uid="uid://c2a8soliruf35" path="res://systems/dash/dash_time_dilation.tres" id="2_2q0ik"] [ext_resource type="Resource" uid="uid://bl5crtu1gkrtr" path="res://systems/inputs/base_mode/base_mode.tres" id="3_cresl"] [ext_resource type="Resource" uid="uid://cpdaw41ah5gic" path="res://systems/inputs/base_mode/rotate_y.tres" id="4_rxwoh"] [ext_resource type="Resource" uid="uid://ccrb5xsnphc8" path="res://systems/inputs/base_mode/rotate_floorplane.tres" id="5_4u7i3"] @@ -64,14 +63,14 @@ MegaJumpStartVelocity = 30.0 MegaJumpHangTimeInFrames = 12 MegaJumpGravityLesseningFactor = 1.2 WallJumpStartVelocity = 8.0 +MaxNumberOfEmpoweredActions = 3 SimpleDashStrength = 15.0 -PoweredDashStrength = 50.0 +PoweredDashStrength = 30.0 AimedDashTime = 0.2 +PostDashSpeed = 30.0 WallHugGravityLesseningFactor = 15.0 WallHugDownwardMaxSpeed = 8.0 WallHugHorizontalDeceleration = 0.5 -MaxNumberOfDashActions = 2 -DashTimeDilationCurve = ExtResource("2_2q0ik") [node name="InputController" type="Node3D" parent="."] script = ExtResource("16_v31n3") @@ -426,6 +425,12 @@ to = NodePath("../Dashing/AimedDash") event = &"aimed_dash" delay_in_seconds = "0.0" +[node name="OnWeaponDash" type="Node" parent="StateChart/Root/Movement"] +script = ExtResource("28_n7qhm") +to = NodePath("../Dashing/ToWeaponDash") +event = &"weapon_dash" +delay_in_seconds = "0.0" + [node name="Mantling" type="Node" parent="StateChart/Root/Movement"] script = ExtResource("27_34snm") @@ -503,6 +508,15 @@ script = ExtResource("27_34snm") [node name="AimedDash" type="Node" parent="StateChart/Root/Movement/Dashing"] script = ExtResource("27_34snm") +[node name="ToWeaponDash" type="Node" parent="StateChart/Root/Movement/Dashing"] +script = ExtResource("27_34snm") + +[node name="ToPlantedWeapon" type="Node" parent="StateChart/Root/Movement/Dashing/ToWeaponDash"] +script = ExtResource("28_n7qhm") +to = NodePath("../../../OnWall/Hanging") +event = &"to_planted" +delay_in_seconds = "0.0" + [node name="Grounded" type="Node" parent="StateChart/Root/Movement"] script = ExtResource("27_34snm") diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index c0df48a..356674c 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -118,6 +118,8 @@ public partial class PlayerController : CharacterBody3D // Dash [ExportGroup("Dash")] + [Export(PropertyHint.Range, "0,5,1,or_greater")] + public int MaxNumberOfEmpoweredActions { get; set; } = 1; // Simple dash [ExportSubgroup("Simple")] [Export(PropertyHint.Range, "0,50,0.1")] @@ -129,9 +131,13 @@ public partial class PlayerController : CharacterBody3D [Export(PropertyHint.Range, "0,100,0.1")] public float PoweredDashStrength { get; set; } = 10f; // Aimed Dash - [ExportSubgroup("Aimed")] + [ExportSubgroup("Special")] [Export(PropertyHint.Range, "0,1,0.01,or_greater")] public float AimedDashTime { get; set; } = 0.1f; + [Export(PropertyHint.Range, "0,100,1,or_greater")] + public float PostDashSpeed { get; set; } = 100f; + [Export(PropertyHint.Range, "0,1,0.01,or_greater")] + public float TimeScaleAimInAir { get; set; } = 0.05f; // Wall hug [ExportGroup("Wall hug")] @@ -145,16 +151,6 @@ public partial class PlayerController : CharacterBody3D private float _targetSpeed; private float _gravity; - [ExportCategory("Other")] - [Export(PropertyHint.Range, "0,1,0.01,or_greater")] - public float TimeScaleAimInAir { get; set; } = 0.05f; - [Export(PropertyHint.Range, "0,5,1,or_greater")] - public int MaxNumberOfDashActions { get; set; } = 1; - - [Export] - public Curve DashTimeDilationCurve { get; set; } - private bool _canDash = true; - private int _empoweredActionsLeft; public int EmpoweredActionsLeft { @@ -167,7 +163,8 @@ public partial class PlayerController : CharacterBody3D } private bool _isWallJumpAvailable = true; - private bool _isActionPerfectlyTimed = false; + private bool _canDash = true; + private bool _shouldMantleOnDashEnded = false; private StateChart _playerState; @@ -217,7 +214,7 @@ public partial class PlayerController : CharacterBody3D // DashIndicator = GetNode("%DashIndicator"); PowerCooldownIndicator = GetNode("%DashCooldownIndicator"); PowerCooldownIndicator.Visible = false; - EmpoweredActionsLeft = MaxNumberOfDashActions; + EmpoweredActionsLeft = MaxNumberOfEmpoweredActions; _targetSpeed = WalkSpeed; // Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D; @@ -330,7 +327,7 @@ public partial class PlayerController : CharacterBody3D HealthSystem.Init(healthSystemParams); Stamina.SetSpeeds(WalkSpeed, WalkSpeed); - EmpoweredActionsLeft = MaxNumberOfDashActions; + EmpoweredActionsLeft = MaxNumberOfEmpoweredActions; /////////////////////////// // Signal setup /////////// @@ -374,7 +371,6 @@ public partial class PlayerController : CharacterBody3D _poweredDash.StateExited += OnPoweredDashFinished; _aimedDash.StateEntered += OnAimedDashStarted; - _aimedDash.StatePhysicsProcessing += HandleAimedDash; _aimedDash.StateExited += OnAimedDashFinished; _simpleDashCooldownTimer.Timeout += DashCooldownTimeout; @@ -432,6 +428,7 @@ public partial class PlayerController : CharacterBody3D } public void HandleWallHanging(float delta) { + GD.Print("Hanging"); WallHang(delta); } @@ -443,27 +440,6 @@ public partial class PlayerController : CharacterBody3D MantleToLocation(MantleSystem.FindMantleInFrontOfPlayer().Unwrap()); return; } - - // if (_grounded.Active || _coyoteEnabled.Active) - // { - // if (_empowerOn.Active && CanPerformEmpoweredAction()) - // { - // PerformEmpoweredAction(); - // PerformJump(JumpTypes.JumpFromDash); - // _playerState.SendEvent("megajump"); - // } - // } - // else if (_doubleJumpEnabled.Active) - // if (_empowerOn.Active && CanPerformEmpoweredAction()) - // { - // PerformEmpoweredAction(); - // PerformJump(JumpTypes.JumpFromDash); - // _playerState.SendEvent("megajump"); - // } - // else - // PerformJump(JumpTypes.DoubleJump); - // else if (_onWall.Active) - // JumpFromWall(_empowerOn.Active); if (_empowerOn.Active && CanPerformEmpoweredAction()) { @@ -633,7 +609,7 @@ public partial class PlayerController : CharacterBody3D public void PowerCooldownExpired() { EmpoweredActionsLeft += 1; - var eventToSend = EmpoweredActionsLeft == MaxNumberOfDashActions ? "fully_charged" : "recharge"; + var eventToSend = EmpoweredActionsLeft == MaxNumberOfEmpoweredActions ? "fully_charged" : "recharge"; _playerState.SendEvent(eventToSend); } @@ -655,10 +631,6 @@ public partial class PlayerController : CharacterBody3D public void OnInputAimPressed() { _playerState.SendEvent("aim_pressed"); - // if (!WeaponSystem.InHandState.Active) - // { - // OnDashStarted(); - // } } public void OnInputAimDown() { @@ -677,7 +649,7 @@ public partial class PlayerController : CharacterBody3D { if (_aiming.Active) { - OnWeaponThrown(); + ThrowWeapon(); } } public void OnInputEmpowerDown() @@ -688,7 +660,6 @@ public partial class PlayerController : CharacterBody3D { _playerState.SendEvent("empower_released"); } - public void OnInputDashPressed() { if (_aiming.Active && CanPerformEmpoweredAction()) @@ -714,18 +685,25 @@ public partial class PlayerController : CharacterBody3D _playerState.SendEvent("dash"); } - public void OnAimingEntered() { - // if (!WeaponSystem.InHandState.Active) - // { - // OnDashStarted(); - // return; - // } - if (CanPerformEmpoweredAction()) - DashSystem.StartPreparingDash(); + if (!CanPerformEmpoweredAction()) + return; - if (!isOnFloorCustom() && CanPerformEmpoweredAction()) + if (WeaponSystem.FlyingState.Active) + { + DashToFlyingWeapon(); + return; + } + + if (WeaponSystem.PlantedState.Active) + { + DashToPlantedWeapon(); + return; + } + + DashSystem.StartPreparingDash(); + if (!isOnFloorCustom()) ReduceTimeScaleWhileAiming(); } public void HandleAiming(float delta) @@ -740,41 +718,75 @@ public partial class PlayerController : CharacterBody3D DashSystem.StopPreparingDash(); } - private bool _shouldMantleOnDashEnded = false; + public void DashToFlyingWeapon() + { + _playerState.SendEvent("cancel_aim"); + _playerState.SendEvent("weapon_dash"); + PerformEmpoweredAction(); + + DashSystem.ShouldMantle = false; + _dashDirection = (WeaponSystem.GlobalPosition - GlobalPosition).Normalized(); + + var dashTween = CreatePositionTween(WeaponSystem.GlobalPosition, AimedDashTime); + dashTween.Finished += DashToFlyingWeaponTweenEnded; + } + + public void DashToFlyingWeaponTweenEnded() + { + // Get the weapon back + GetTree().GetRoot().RemoveChild(WeaponRoot); + AddChild(WeaponRoot); + WeaponRoot.SetGlobalPosition(GlobalPosition); + WeaponSystem.ResetWeapon(); + + var vel = _dashDirection * PostDashSpeed; + SetVelocity(vel); + _playerState.SendEvent("dash_finished"); + } + + public void DashToPlantedWeapon() + { + _playerState.SendEvent("cancel_aim"); + _playerState.SendEvent("weapon_dash"); + PerformEmpoweredAction(); + + DashSystem.ShouldMantle = false; + var dashLocation = WeaponSystem.PlantLocation; + if (WeaponSystem.IsPlantedInWall()) + dashLocation += WeaponSystem.PlantNormal * _playerRadius; + if (WeaponSystem.IsPlantedUnderPlatform()) + dashLocation += Vector3.Down * _playerHeight; + + var dashTween = CreatePositionTween(dashLocation, AimedDashTime); + dashTween.Finished += DashToPlantedWeaponTweenEnded; + } + + public void DashToPlantedWeaponTweenEnded() + { + // Store the weapon state before resetting it + var isPlantedOnWall = WeaponSystem.IsPlantedInWall(); + var isPlantedUnderPlatform = WeaponSystem.IsPlantedUnderPlatform(); + var shouldDashToHanging = isPlantedOnWall || isPlantedUnderPlatform; + + // Get the weapon back + GetTree().GetRoot().RemoveChild(WeaponRoot); + AddChild(WeaponRoot); + WeaponRoot.SetGlobalPosition(GlobalPosition); + WeaponSystem.ResetWeapon(); + + var resultingEvent = shouldDashToHanging ? "to_planted" : "dash_finished"; + _playerState.SendEvent(resultingEvent); + } public void OnAimedDashStarted() { - // if (WeaponSystem.FlyingState.Active) - // { - // DashSystem.ShouldMantle = false; - // DashSystem.PlannedPlayerLocation = WeaponSystem.GlobalPosition; - // } - // else if (WeaponSystem.PlantedState.Active) - // { - // DashSystem.ShouldMantle = false; - // var dashLocation = WeaponSystem.PlantLocation; - // if (WeaponSystem.IsPlantedInWall()) - // { - // dashLocation += WeaponSystem.PlantNormal * 0.5f; // Player radius - // } - // - // if (WeaponSystem.IsPlantedUnderPlatform()) - // { - // dashLocation += Vector3.Down * 1f; // Player height - // } - // - // DashSystem.PlannedPlayerLocation = dashLocation; - // } - // _dashDirection = (DashSystem.PlannedPlayerLocation - GlobalPosition).Normalized(); - // Adjusting for player height, where the middle of the capsule should get to the dash location instead of the // feet of the capsule - // GD.Print(DashSystem.CollisionNormal); var correction = DashSystem.CollisionNormal == Vector3.Down ? _playerHeight : DashSystem.DashCastRadius; var correctedLocation = DashSystem.PlannedLocation + Vector3.Down * correction; var dashTween = CreatePositionTween(correctedLocation, AimedDashTime); - dashTween.TweenMethod(Callable.From(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime); + // dashTween.TweenMethod(Callable.From(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime); dashTween.Finished += AimedDashTweenEnded; _shouldMantleOnDashEnded = DashSystem.ShouldMantle; @@ -791,19 +803,27 @@ public partial class PlayerController : CharacterBody3D return tween; } - - public void HandleAimedDash(float delta) - { - } - - public void AimedDashTweenOngoing(float progress) - { - } public void AimedDashTweenEnded() { _playerState.SendEvent("dash_finished"); } + + public void ThrowWeapon() + { + _playerState.SendEvent("cancel_aim"); + + RemoveChild(WeaponRoot); + GetTree().GetRoot().AddChild(WeaponRoot); + WeaponRoot.SetGlobalPosition(GlobalPosition); + + var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.PlannedLocation; + WeaponSystem.ThrowWeapon( + weaponTargetLocation, + DashSystem.HasHit, + DashSystem.CollisionPoint, + DashSystem.CollisionNormal); + } public void OnAimedDashFinished() { @@ -848,7 +868,9 @@ public partial class PlayerController : CharacterBody3D public void OnPoweredDashFinished() { - // Try mantling here + // Try mantling but don't know if this is useful + if (CanMantle()) + MantleToLocation(MantleSystem.FindMantleInFrontOfPlayer().Unwrap()); } public void FinishPoweredDash() @@ -902,96 +924,6 @@ public partial class PlayerController : CharacterBody3D _playerState.SendEvent("grounded"); } - // Dashing and weapon throwing - public void OnDashStarted() - { - if (!CanPerformEmpoweredAction()) - { - _playerState.SendEvent("aim_canceled"); - _playerState.SendEvent("dash_ended"); - DashSystem.StopPreparingDash(); - return; - } - - PerformEmpoweredAction(); - if (WeaponSystem.FlyingState.Active) - { - DashSystem.ShouldMantle = false; - DashSystem.PlannedLocation = WeaponSystem.GlobalPosition; - } - else if (WeaponSystem.PlantedState.Active) - { - DashSystem.ShouldMantle = false; - var dashLocation = WeaponSystem.PlantLocation; - if (WeaponSystem.IsPlantedInWall()) - { - dashLocation += WeaponSystem.PlantNormal * 0.5f; // Player radius - } - - if (WeaponSystem.IsPlantedUnderPlatform()) - { - dashLocation += Vector3.Down * 1f; // Player height - } - - DashSystem.PlannedLocation = dashLocation; - } - _dashDirection = (DashSystem.PlannedLocation - GlobalPosition).Normalized(); - } - public void OnDashEnded() - { - // Regular dash - if (WeaponSystem.InHandState.Active) - { - _playerState.SendEvent("dash_ended"); - return; - } - - // Store the weapon state before resetting it - var isPlantedOnWall = WeaponSystem.IsPlantedInWall(); - var isPlantedUnderPlatform = WeaponSystem.IsPlantedUnderPlatform(); - var shouldDashToHanging = isPlantedOnWall || isPlantedUnderPlatform; - var isFlying = WeaponSystem.FlyingState.Active; - - // Get the weapon back - GetTree().GetRoot().RemoveChild(WeaponRoot); - AddChild(WeaponRoot); - WeaponRoot.SetGlobalPosition(GlobalPosition); - WeaponSystem.ResetWeapon(); - - if (isFlying) - { - var vel = _dashDirection * DashSystem.PostDashSpeed; - SetVelocity(vel); - _playerState.SendEvent("dash_ended"); - return; // In case states aren't exclusives - } - - if (shouldDashToHanging) - { - _playerState.SendEvent("dash_to_planted"); - return; // In case states aren't exclusives - } - - // Weapon planted anywhere else - _playerState.SendEvent("dash_ended"); - } - public void OnWeaponThrown() - { - DashSystem.StopPreparingDash(); - _playerState.SendEvent("cancel_aim"); - - RemoveChild(WeaponRoot); - GetTree().GetRoot().AddChild(WeaponRoot); - WeaponRoot.SetGlobalPosition(GlobalPosition); - - var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.TargetLocation; - WeaponSystem.ThrowWeapon( - weaponTargetLocation, - DashSystem.HasHit, - DashSystem.CollisionPoint, - DashSystem.CollisionNormal); - } - // Regular processes public void HandleWeaponInHand(float delta) { @@ -1142,10 +1074,7 @@ public partial class PlayerController : CharacterBody3D /////////////////////////// public override void _PhysicsProcess(double delta) { - TweenQueueSystem.ProcessTweens(); - LookAround(); - // MoveAround(delta); CameraModifications((float) delta); HandleStairs((float) delta); } diff --git a/systems/dash/DashSystem.cs b/systems/dash/DashSystem.cs index 089519e..7ba6cba 100644 --- a/systems/dash/DashSystem.cs +++ b/systems/dash/DashSystem.cs @@ -74,25 +74,6 @@ public partial class DashSystem: Node3D _dashIndicatorAnim = GetNode("DashIndicator/AnimationPlayer"); } - private Vector3 RecurseThroughCollisions(Vector3 previousCollisionPoint, Vector3 previousNormal, int recursionDepth) - { - if (recursionDepth == 0) - return previousCollisionPoint; - - var startPoint = previousCollisionPoint + previousNormal*_playerHeight; - _playerCast3D.SetGlobalPosition(startPoint); - _playerCast3D.SetTargetPosition(-previousNormal*_playerRadius); - - var hasHit = _playerCast3D.IsColliding(); - if (!hasHit) - return previousCollisionPoint; - - return RecurseThroughCollisions( - _playerCast3D.GetCollisionPoint(0), - _playerCast3D.GetCollisionNormal(0), - recursionDepth - 1); - } - private DashLocation ComputeDashLocation() { var targetLocation = _dashCast3D.ToGlobal(_dashCast3D.TargetPosition); @@ -109,18 +90,6 @@ public partial class DashSystem: Node3D var globalSweepPath = targetLocation - _dashCast3D.GlobalPosition; var locationAlongPath = _dashCast3D.GlobalPosition + globalSweepPath * fraction; return new DashLocation(true, locationAlongPath, collisionPoint, collisionNormal); - - // // Pushes the point down when dashing to under a platform so head doesn't clip - // var maxPushDownDistance = 0.9f; - // var correctionProportion = (float) Mathf.Remap(CollisionNormal.Y, -0.5, -1, 0, 1); - // var proportion = (float)Mathf.Remap(_dashCast3D.GlobalRotation.X, 0, 1.57, 0, 1); - // var finalLocation = locationAlongPath - // + CollisionNormal - // * maxPushDownDistance - // * Mathf.Clamp(proportion, 0, 1) - // * Mathf.Clamp(correctionProportion, 0, 1); - // - // return new DashLocation(true, finalLocation); } public void PrepareDash() diff --git a/systems/weapon/WeaponSystem.cs b/systems/weapon/WeaponSystem.cs index 9a995a0..7d1c46b 100644 --- a/systems/weapon/WeaponSystem.cs +++ b/systems/weapon/WeaponSystem.cs @@ -54,7 +54,7 @@ public partial class WeaponSystem : RigidBody3D PlantLocation = collisionLocation; PlantNormal = collisionNormal; LookAt(end); - + var tween = _tweenQueueSystem.TweenToLocation(new TweenQueueSystem.TweenInputs(end, StraightThrowDuration)); if (hasHit) tween.Finished += PlantWeaponInWall;