diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index c77a4079..edccddaf 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -228,7 +228,7 @@ public partial class PlayerController : CharacterBody3D private float _playerHeight; private float _playerRadius; - private bool _isJumpInputPressed = false; + private bool _isJumpInputPressed; private float _lookSensitivityMultiplier = 1.0f; private float _mouseSensitivityMultiplier = 1.0f; @@ -746,6 +746,9 @@ public partial class PlayerController : CharacterBody3D } private Path _mantlePath; + private bool _customMantle; + private Transform3D _customMantleStartTransform; + private Curve3D _customMantleCurve; public void OnMantleStarted() { HeadSystem.OnMantle(); @@ -755,10 +758,12 @@ public partial class PlayerController : CharacterBody3D { GD.PrintErr("Failed to instantiate MantlePath"); return; - }; - + } + + var transform = _customMantle ? _customMantleStartTransform : MantleSystem.GlobalTransform; + var curve = _customMantle ? _customMantleCurve : MantleSystem.MantleCurve; GetTree().GetRoot().AddChild(_mantlePath); - _mantlePath.Setup(MantleSystem.GlobalTransform, MantleSystem.MantleCurve); + _mantlePath.Setup(transform, curve); var tween = GetTree().CreateTween(); tween.SetTrans(Tween.TransitionType.Linear); @@ -771,15 +776,22 @@ public partial class PlayerController : CharacterBody3D { GlobalPosition = _mantlePath.Target.GlobalPosition; } + + public void SimpleDash() + { + SetVelocity(GetInputGlobalHDirection() * SimpleDashStrength); + } public void MantleFinished() { _mantlePath.Teardown(); - var direction = GetInputGlobalHDirection(); + var direction = GetMoveInput(); if (direction.Length() > 0) { - SetVelocity(direction * SimpleDashStrength); + SimpleDash(); } + + _customMantle = false; _playerState.SendEvent("grounded"); } @@ -1034,7 +1046,6 @@ public partial class PlayerController : CharacterBody3D } private Vector3 _preDashVelocity = Vector3.Zero; - public void OnAimedDashStarted() { // Adjusting for player height, where the middle of the capsule should get to the dash location instead of the @@ -1048,9 +1059,10 @@ public partial class PlayerController : CharacterBody3D var dashTween = CreatePositionTween(correctedLocation, AimedDashTime); // dashTween.TweenMethod(Callable.From(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime); dashTween.Finished += AimedDashTweenEnded; - - _shouldMantleOnDashEnded = DashSystem.ShouldMantle; - _mantleLocation = DashSystem.PlannedMantleLocation; + + _customMantle = DashSystem.ShouldMantle; + _customMantleCurve = DashSystem.MantleSystem.MantleCurve; + _customMantleStartTransform = DashSystem.MantleSystem.GlobalTransform; } Tween CreatePositionTween(Vector3 targetLocation, float tweenTime) @@ -1069,6 +1081,13 @@ public partial class PlayerController : CharacterBody3D _playerState.SendEvent("dash_finished"); } + public void OnAimedDashFinished() + { + var postDashVelocity = _preDashVelocity.Length() > PostDashSpeed ? PostDashSpeed : _preDashVelocity.Length(); + Velocity = _dashDirection * postDashVelocity; + if (_customMantle) _playerState.SendEvent("mantle"); + } + public void PlaceWeaponForTutorial() { if (TutorialDone) @@ -1107,29 +1126,12 @@ public partial class PlayerController : CharacterBody3D DashSystem.CollisionNormal); } - public void OnAimedDashFinished() - { - var postDashVelocity = _preDashVelocity.Length() > PostDashSpeed ? PostDashSpeed : _preDashVelocity.Length(); - Velocity = _dashDirection * postDashVelocity; - - if (_shouldMantleOnDashEnded) - { - // TODO update post dash mantle - // MantleToLocation(_mantleLocation); - - } - } - public void OnSimpleDashStarted() { if (!_canDash) return; _canDash = false; - - var dashStrength = SimpleDashStrength; - - var direction = GetInputGlobalHDirection(); - SetVelocity(direction * dashStrength); + SimpleDash(); } public void HandleSimpleDash(float delta) diff --git a/systems/dash/DashSystem.cs b/systems/dash/DashSystem.cs index a22e6ab4..bb2a8f40 100644 --- a/systems/dash/DashSystem.cs +++ b/systems/dash/DashSystem.cs @@ -20,10 +20,10 @@ public partial class DashSystem: Node3D public bool ShouldMantle { get; set; } public Vector3 PlannedMantleLocation { get; set; } + public MantleSystem MantleSystem { get; set; } private Node3D _head; private ShapeCast3D _dashCast3D; - private ShapeCast3D _playerCast3D; private Camera3D _camera; private Vector3 _dashDirection = Vector3.Zero; @@ -31,7 +31,6 @@ public partial class DashSystem: Node3D private MeshInstance3D _dashDropIndicator; private MeshInstance3D _dashDropLocationIndicator; - private MantleSystem _mantleSystem; private MeshInstance3D _dashTarget; private CpuParticles3D _dashIndicator; private AnimationPlayer _dashIndicatorAnim; @@ -47,9 +46,6 @@ public partial class DashSystem: Node3D public delegate void DashProgressEventHandler(float progress); private Vector3 _globalDashPosition = Vector3.Zero; - - private float _playerHeight; - private float _playerRadius; public float DashCastRadius { get; set; } @@ -65,16 +61,11 @@ public partial class DashSystem: Node3D _dashDropLocationIndicator = GetNode("DashDropLocationIndicator"); _dashDropLocationIndicator.Visible = false; - _playerCast3D = GetNode("PlayerShapeCast3D"); - var playerShape = _playerCast3D.GetShape() as CapsuleShape3D; - _playerHeight = playerShape!.Height; - _playerRadius = playerShape!.Radius; - _head = head; _camera = camera; - _mantleSystem = GetNode("MantleSystem"); - _mantleSystem.Init(); + MantleSystem = GetNode("MantleSystem"); + MantleSystem.Init(); _dashTarget = GetNode("DashTarget"); _dashTarget.SetVisible(false); @@ -109,14 +100,15 @@ public partial class DashSystem: Node3D (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; + // TODO: Position mantle system to planned location, aligned with ground planned and facing the same way as the dash + // Then query it being careful when dashing underneath a platform and such + MantleSystem.SetGlobalPosition(PlannedLocation); + MantleSystem.SetRotation(new Vector3( + MantleSystem.Rotation.X, + _head.Rotation.Y, + MantleSystem.Rotation.Z)); + MantleSystem.ProcessMantle(false); + ShouldMantle = MantleSystem.IsMantlePossible; // Setup dash target var targetColor = HasHit ? new Color(1f, 0.2f, 0.2f) : new Color(1f, 1f, 1f); @@ -124,7 +116,7 @@ public partial class DashSystem: Node3D var targetMaterial = (StandardMaterial3D) _dashTarget.GetSurfaceOverrideMaterial(0); targetMaterial.SetAlbedo(targetColor); _dashTarget.SetVisible(true); - var targetLocation = ShouldMantle ? PlannedMantleLocation : PlannedLocation; + var targetLocation = ShouldMantle ? MantleSystem.FirstMantleProfilePoint : PlannedLocation; _dashTarget.SetGlobalPosition(targetLocation); var shouldShowDropIndicator = !HasHit && !ShouldMantle; @@ -160,6 +152,5 @@ public partial class DashSystem: Node3D public void StartPreparingDash() { _dashTarget.SetVisible(true); - } } diff --git a/systems/dash/dash_system.tscn b/systems/dash/dash_system.tscn index 954759c8..88cf2357 100644 --- a/systems/dash/dash_system.tscn +++ b/systems/dash/dash_system.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=10 format=3 uid="uid://cqduhd4opgwvm"] +[gd_scene load_steps=9 format=3 uid="uid://cqduhd4opgwvm"] [ext_resource type="Script" uid="uid://dwoppk8j5fxeg" path="res://systems/dash/DashSystem.cs" id="1_hwig2"] -[ext_resource type="Shape3D" uid="uid://keseacdcooot" path="res://player_controller/resources/PlayerShape.tres" id="2_jngg2"] [ext_resource type="PackedScene" uid="uid://wq1okogkhc5l" path="res://systems/mantle/mantle_system.tscn" id="2_pff7b"] [ext_resource type="PackedScene" uid="uid://hd0868f4pb63" path="res://systems/dash/dash_indicator.tscn" id="2_tqt6i"] @@ -24,16 +23,8 @@ outer_radius = 0.5 script = ExtResource("1_hwig2") DashIndicatorScene = ExtResource("2_tqt6i") -[node name="PlayerShapeCast3D" type="ShapeCast3D" parent="."] -visible = false -shape = ExtResource("2_jngg2") -target_position = Vector3(0, 0, 0) -collision_mask = 2 -debug_shape_custom_color = Color(0.863327, 0.636844, 0, 1) - [node name="DashCast3D" type="ShapeCast3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.6, 0) -visible = false shape = SubResource("SphereShape3D_jngg2") target_position = Vector3(0, 0, -12) max_results = 1 @@ -42,7 +33,6 @@ debug_shape_custom_color = Color(0.911631, 0.11884, 0.656218, 1) [node name="DashCastDrop" type="ShapeCast3D" parent="."] transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 1.6, 0) -visible = false shape = SubResource("SphereShape3D_jngg2") target_position = Vector3(0, 0, -50) max_results = 1 @@ -54,7 +44,6 @@ mesh = SubResource("SphereMesh_qu4wy") surface_material_override/0 = SubResource("StandardMaterial3D_v31n3") [node name="MantleSystem" parent="." instance=ExtResource("2_pff7b")] -visible = false MantleEndLocationDistanceFromWall = 0.25 MantleHeightCastStart = 2.0 diff --git a/systems/mantle/MantleSystem.cs b/systems/mantle/MantleSystem.cs index 4eac9b50..147f6d2f 100644 --- a/systems/mantle/MantleSystem.cs +++ b/systems/mantle/MantleSystem.cs @@ -18,6 +18,7 @@ public partial class MantleSystem: Node3D private ShapeCast3D _inAirWallDetect; private ShapeCast3D _groundedWallDetect; public Curve3D MantleCurve { get; private set; } + public Vector3 FirstMantleProfilePoint { get; private set; } = Vector3.Zero; public bool IsMantlePossible { get; private set; } = false; public const int WallProfileCastCount = 7; @@ -86,6 +87,7 @@ public partial class MantleSystem: Node3D if (isCollisionSameAsTarget || isCollidingWithWall) continue; // We have a valid collision + if (!hasFirstProfileHit) FirstMantleProfilePoint = profilePoint; hasFirstProfileHit = true; MantleCurve.AddPoint(ToLocal(profilePoint)); } @@ -93,34 +95,4 @@ public partial class MantleSystem: Node3D IsMantlePossible = true; } - - public Option FindMantle() - { - if (!_wallInFrontCast3D.IsColliding()) - { - return Option.None; - } - if (_wallInFrontCast3D.GetCollisionNormal(0).Y > 0.8f) - { - return Option.None; - } - - var collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0); - var collisionNormal = _wallInFrontCast3D.GetCollisionNormal(0); - return FindMantleLocationAtPoint(collisionPoint, collisionNormal); - } - - public Option FindMantleLocationAtPoint(Vector3 point, Vector3 wallNormal) - { - var horizontalEndLocation = point - wallNormal * MantleEndLocationDistanceFromWall; - var shapeCastStartLocation = horizontalEndLocation + Vector3.Up * MantleHeightCastStart; - - _mantleCast3D.SetGlobalPosition(shapeCastStartLocation); - var targetLocation = Vector3.Down * MantleHeightCastStart + Vector3.Up * MaxStepHeight; - _mantleCast3D.SetTargetPosition(targetLocation); - - if (_mantleCast3D.IsColliding() && _mantleCast3D.GetCollisionNormal(0).Y >= 0.1f) - return Option.Some(_mantleCast3D.GetCollisionPoint(0)); - return Option.None; - } }