mantling seems to work

This commit is contained in:
2025-09-11 18:12:34 +02:00
parent 285365becf
commit 49ba007613
2 changed files with 38 additions and 43 deletions

View File

@ -71,6 +71,9 @@ public partial class PlayerController : CharacterBody3D
public float DecelerationAir = 1.0f; public float DecelerationAir = 1.0f;
[Export(PropertyHint.Range, "0,10,0.01,or_greater")] [Export(PropertyHint.Range, "0,10,0.01,or_greater")]
public float Weight { get; set; } = 3.0f; 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 // Jump
[ExportGroup("Jump")] [ExportGroup("Jump")]
@ -437,7 +440,7 @@ public partial class PlayerController : CharacterBody3D
{ {
if (CanMantle()) if (CanMantle())
{ {
Mantle(); MantleToLocation(MantleSystem.FindMantleInFrontOfPlayer().Unwrap());
return; return;
} }
@ -652,10 +655,10 @@ public partial class PlayerController : CharacterBody3D
public void OnInputAimPressed() public void OnInputAimPressed()
{ {
_playerState.SendEvent("aim_pressed"); _playerState.SendEvent("aim_pressed");
if (!WeaponSystem.InHandState.Active) // if (!WeaponSystem.InHandState.Active)
{ // {
OnDashStarted(); // OnDashStarted();
} // }
} }
public void OnInputAimDown() public void OnInputAimDown()
{ {
@ -737,6 +740,8 @@ public partial class PlayerController : CharacterBody3D
DashSystem.StopPreparingDash(); DashSystem.StopPreparingDash();
} }
private bool _shouldMantleOnDashEnded = false;
public void OnAimedDashStarted() public void OnAimedDashStarted()
{ {
// if (WeaponSystem.FlyingState.Active) // if (WeaponSystem.FlyingState.Active)
@ -767,16 +772,24 @@ public partial class PlayerController : CharacterBody3D
// GD.Print(DashSystem.CollisionNormal); // GD.Print(DashSystem.CollisionNormal);
var correction = DashSystem.CollisionNormal == Vector3.Down ? _playerHeight : DashSystem.DashCastRadius; var correction = DashSystem.CollisionNormal == Vector3.Down ? _playerHeight : DashSystem.DashCastRadius;
var correctedLocation = DashSystem.PlannedLocation + Vector3.Down * correction; var correctedLocation = DashSystem.PlannedLocation + Vector3.Down * correction;
var dashTween = GetTree().CreateTween(); var dashTween = CreatePositionTween(correctedLocation, AimedDashTime);
dashTween.SetParallel();
dashTween.SetTrans(Tween.TransitionType.Cubic);
dashTween.SetEase(Tween.EaseType.InOut);
dashTween.TweenProperty(this, "global_position", correctedLocation, AimedDashTime);
dashTween.TweenMethod(Callable.From<float>(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime); dashTween.TweenMethod(Callable.From<float>(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime);
dashTween.Finished += AimedDashTweenEnded; 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) public void HandleAimedDash(float delta)
@ -794,8 +807,8 @@ public partial class PlayerController : CharacterBody3D
public void OnAimedDashFinished() public void OnAimedDashFinished()
{ {
if (DashSystem.ShouldMantle) if (_shouldMantleOnDashEnded)
Mantle(); MantleToLocation(_mantleLocation);
} }
public void OnSimpleDashStarted() public void OnSimpleDashStarted()
@ -874,33 +887,16 @@ public partial class PlayerController : CharacterBody3D
} }
// Mantling // Mantling
public void Mantle()
{
_playerState.SendEvent("mantle");
var optionTween = FindMantle();
if (optionTween.IsSome(out var tween))
tween.Finished += MantleFinished;
}
public bool CanMantle() public bool CanMantle()
{ {
var mantleLocationResult = MantleSystem.FindMantleInFrontOfPlayer(); var mantleLocationResult = MantleSystem.FindMantleInFrontOfPlayer();
return mantleLocationResult.IsSome(out _); return mantleLocationResult.IsSome(out _);
} }
public void MantleToLocation(Vector3 location)
public Option<Tween> FindMantle()
{ {
var mantleLocationResult = MantleSystem.FindMantleInFrontOfPlayer(); var mantleTween = CreatePositionTween(location, MantleTime);
if (mantleLocationResult.IsSome(out var mantleLocation)) mantleTween.Finished += MantleFinished;
{
var duration = 0.1f * mantleLocation.DistanceTo(Position);
var tween = TweenQueueSystem.TweenToLocation(new TweenQueueSystem.TweenInputs(mantleLocation, duration));
return tween.Some();
}
return Option<Tween>.None;
} }
public void MantleFinished() public void MantleFinished()
{ {
_playerState.SendEvent("grounded"); _playerState.SendEvent("grounded");

View File

@ -131,16 +131,15 @@ public partial class DashSystem: Node3D
_camera.Rotation.Z)); _camera.Rotation.Z));
(HasHit, PlannedLocation, CollisionPoint, CollisionNormal) = ComputeDashLocation(); (HasHit, PlannedLocation, CollisionPoint, CollisionNormal) = ComputeDashLocation();
ShouldMantle = false; ShouldMantle = false;
// var mantleLocation = Vector3.Zero; var mantleLocation = Vector3.Zero;
// if (HasHit && Mathf.Abs(CollisionNormal.Y) < 0.5f) if (HasHit && Mathf.Abs(CollisionNormal.Y) < 0.5f)
// { {
// var mantleResult = _mantleSystem.FindMantleLocationAtPoint(PlannedLocation, CollisionNormal); var mantleResult = _mantleSystem.FindMantleLocationAtPoint(PlannedLocation, CollisionNormal);
// ShouldMantle = mantleResult.IsSome(out mantleLocation); ShouldMantle = mantleResult.IsSome(out mantleLocation);
// } }
// PlannedMantleLocation = mantleLocation; PlannedMantleLocation = mantleLocation;
// Setup dash target // Setup dash target
var targetColor = HasHit ? new Color(1f, 0.2f, 0.2f) : new Color(1f, 1f, 1f); var targetColor = HasHit ? new Color(1f, 0.2f, 0.2f) : new Color(1f, 1f, 1f);