diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index 94e64d3..c0df48a 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -71,6 +71,9 @@ public partial class PlayerController : CharacterBody3D public float DecelerationAir = 1.0f; [Export(PropertyHint.Range, "0,10,0.01,or_greater")] public float Weight { get; set; } = 3.0f; + [ExportGroup("Mantle")] + [Export(PropertyHint.Range, "0,1,0.01,or_greater")] + public float MantleTime { get; set; } = 0.1f; // Jump [ExportGroup("Jump")] @@ -437,7 +440,7 @@ public partial class PlayerController : CharacterBody3D { if (CanMantle()) { - Mantle(); + MantleToLocation(MantleSystem.FindMantleInFrontOfPlayer().Unwrap()); return; } @@ -652,10 +655,10 @@ public partial class PlayerController : CharacterBody3D public void OnInputAimPressed() { _playerState.SendEvent("aim_pressed"); - if (!WeaponSystem.InHandState.Active) - { - OnDashStarted(); - } + // if (!WeaponSystem.InHandState.Active) + // { + // OnDashStarted(); + // } } public void OnInputAimDown() { @@ -737,6 +740,8 @@ public partial class PlayerController : CharacterBody3D DashSystem.StopPreparingDash(); } + private bool _shouldMantleOnDashEnded = false; + public void OnAimedDashStarted() { // if (WeaponSystem.FlyingState.Active) @@ -767,16 +772,24 @@ public partial class PlayerController : CharacterBody3D // GD.Print(DashSystem.CollisionNormal); var correction = DashSystem.CollisionNormal == Vector3.Down ? _playerHeight : DashSystem.DashCastRadius; var correctedLocation = DashSystem.PlannedLocation + Vector3.Down * correction; - - var dashTween = GetTree().CreateTween(); - dashTween.SetParallel(); - dashTween.SetTrans(Tween.TransitionType.Cubic); - dashTween.SetEase(Tween.EaseType.InOut); - - dashTween.TweenProperty(this, "global_position", correctedLocation, AimedDashTime); + + var dashTween = CreatePositionTween(correctedLocation, AimedDashTime); dashTween.TweenMethod(Callable.From(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime); - dashTween.Finished += AimedDashTweenEnded; + + _shouldMantleOnDashEnded = DashSystem.ShouldMantle; + _mantleLocation = DashSystem.PlannedMantleLocation; + } + + Tween CreatePositionTween(Vector3 targetLocation, float tweenTime) + { + var tween = GetTree().CreateTween(); + tween.SetParallel(); + tween.SetTrans(Tween.TransitionType.Cubic); + tween.SetEase(Tween.EaseType.InOut); + tween.TweenProperty(this, "global_position", targetLocation, tweenTime); + + return tween; } public void HandleAimedDash(float delta) @@ -794,8 +807,8 @@ public partial class PlayerController : CharacterBody3D public void OnAimedDashFinished() { - if (DashSystem.ShouldMantle) - Mantle(); + if (_shouldMantleOnDashEnded) + MantleToLocation(_mantleLocation); } public void OnSimpleDashStarted() @@ -874,33 +887,16 @@ public partial class PlayerController : CharacterBody3D } // Mantling - public void Mantle() - { - _playerState.SendEvent("mantle"); - - var optionTween = FindMantle(); - if (optionTween.IsSome(out var tween)) - tween.Finished += MantleFinished; - } - public bool CanMantle() { var mantleLocationResult = MantleSystem.FindMantleInFrontOfPlayer(); return mantleLocationResult.IsSome(out _); } - - public Option FindMantle() + public void MantleToLocation(Vector3 location) { - var mantleLocationResult = MantleSystem.FindMantleInFrontOfPlayer(); - if (mantleLocationResult.IsSome(out var mantleLocation)) - { - var duration = 0.1f * mantleLocation.DistanceTo(Position); - var tween = TweenQueueSystem.TweenToLocation(new TweenQueueSystem.TweenInputs(mantleLocation, duration)); - return tween.Some(); - } - return Option.None; + var mantleTween = CreatePositionTween(location, MantleTime); + mantleTween.Finished += MantleFinished; } - public void MantleFinished() { _playerState.SendEvent("grounded"); diff --git a/systems/dash/DashSystem.cs b/systems/dash/DashSystem.cs index 77cec55..089519e 100644 --- a/systems/dash/DashSystem.cs +++ b/systems/dash/DashSystem.cs @@ -131,16 +131,15 @@ public partial class DashSystem: Node3D _camera.Rotation.Z)); (HasHit, PlannedLocation, CollisionPoint, CollisionNormal) = ComputeDashLocation(); - ShouldMantle = false; - // var mantleLocation = Vector3.Zero; - // if (HasHit && Mathf.Abs(CollisionNormal.Y) < 0.5f) - // { - // var mantleResult = _mantleSystem.FindMantleLocationAtPoint(PlannedLocation, CollisionNormal); - // ShouldMantle = mantleResult.IsSome(out mantleLocation); - // } - // PlannedMantleLocation = mantleLocation; + var mantleLocation = Vector3.Zero; + if (HasHit && Mathf.Abs(CollisionNormal.Y) < 0.5f) + { + var mantleResult = _mantleSystem.FindMantleLocationAtPoint(PlannedLocation, CollisionNormal); + ShouldMantle = mantleResult.IsSome(out mantleLocation); + } + PlannedMantleLocation = mantleLocation; // Setup dash target var targetColor = HasHit ? new Color(1f, 0.2f, 0.2f) : new Color(1f, 1f, 1f);