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;
[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<float>(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<Tween> 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<Tween>.None;
var mantleTween = CreatePositionTween(location, MantleTime);
mantleTween.Finished += MantleFinished;
}
public void MantleFinished()
{
_playerState.SendEvent("grounded");