mantling after aimed dash with new mantle system

This commit is contained in:
2025-12-21 16:44:35 +01:00
parent e0fc301414
commit cf52af4237
4 changed files with 46 additions and 92 deletions

View File

@@ -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);
@@ -772,14 +777,21 @@ 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
@@ -1049,8 +1060,9 @@ public partial class PlayerController : CharacterBody3D
// dashTween.TweenMethod(Callable.From<float>(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)

View File

@@ -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;
@@ -48,9 +47,6 @@ public partial class DashSystem: Node3D
private Vector3 _globalDashPosition = Vector3.Zero;
private float _playerHeight;
private float _playerRadius;
public float DashCastRadius { get; set; }
public void Init(Node3D head, Camera3D camera)
@@ -65,16 +61,11 @@ public partial class DashSystem: Node3D
_dashDropLocationIndicator = GetNode<MeshInstance3D>("DashDropLocationIndicator");
_dashDropLocationIndicator.Visible = false;
_playerCast3D = GetNode<ShapeCast3D>("PlayerShapeCast3D");
var playerShape = _playerCast3D.GetShape() as CapsuleShape3D;
_playerHeight = playerShape!.Height;
_playerRadius = playerShape!.Radius;
_head = head;
_camera = camera;
_mantleSystem = GetNode<MantleSystem>("MantleSystem");
_mantleSystem.Init();
MantleSystem = GetNode<MantleSystem>("MantleSystem");
MantleSystem.Init();
_dashTarget = GetNode<MeshInstance3D>("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);
}
}

View File

@@ -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

View File

@@ -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<Vector3> FindMantle()
{
if (!_wallInFrontCast3D.IsColliding())
{
return Option<Vector3>.None;
}
if (_wallInFrontCast3D.GetCollisionNormal(0).Y > 0.8f)
{
return Option<Vector3>.None;
}
var collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0);
var collisionNormal = _wallInFrontCast3D.GetCollisionNormal(0);
return FindMantleLocationAtPoint(collisionPoint, collisionNormal);
}
public Option<Vector3> 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<Vector3>.None;
}
}