movement momentum tweaks

This commit is contained in:
Lilith Schier 2026-09-06 15:58:17 +02:00
parent 5b593c9bcc
commit 5f667d6c1c
4 changed files with 71 additions and 28 deletions

File diff suppressed because one or more lines are too long

View file

@ -15,19 +15,19 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
/// The speed decay used when the player continues movement in the direction they're going.
/// </summary>
[Export(PropertyHint.None, "suffix:s⁻¹")]
public float GroundedSpeedDecay { get; set; } = 0.3f;
public float GroundedSpeedDecay { get; set; } = 0.6f;
[Export(PropertyHint.None, "suffix:s⁻¹")]
public float GroundedSpeedStopDecay { get; set; } = 0.005f;
[Export(PropertyHint.None, "suffix:px/s")]
public float WalkMaxSpeed { get; set; } = 160.0f;
public float WalkMaxSpeed { get; set; } = 150.0f;
[Export(PropertyHint.None, "suffix:px/s")]
public float AirMaxSpeed { get; set; } = 160.0f;
public float AirMaxSpeed { get; set; } = 150.0f;
[Export(PropertyHint.None, "suffix:px/s")]
public float WaterMaxSpeed { get; set; } = 180.0f;
public float WaterMaxSpeed { get; set; } = 190.0f;
[Export(PropertyHint.None, "suffix:px/s²")]
public float WalkAccel { get; set; } = 800.0f;
@ -45,7 +45,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
public float SlashSpeedBoost { get; set; } = 90.0f;
[Export(PropertyHint.None, "suffix:px/s")]
public float DashSpeed { get; set; } = 400.0f;
public float DashSpeed { get; set; } = 500.0f;
/// <summary>The angle difference from perfect left/right that still counts.</summary>
[Export(PropertyHint.Range, "0,360,0.1,radians_as_degrees")]
@ -89,6 +89,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
[Node] private Timer JumpTimer { get; set; } = null!;
[Node] private Timer WallJumpTimer { get; set; } = null!;
[Node] private Timer JumpAllowedTimer { get; set; } = null!;
[Node] private Timer WallJumpAllowedTimer { get; set; } = null!;
[Node] private Timer WaterJumpAllowedTimer { get; set; } = null!;
[Node] private Timer DashTimer { get; set; } = null!;
[Node] private Timer DashDirectionChangeTimer { get; set; } = null!;
@ -110,7 +111,10 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
SubmersedSensor.AreaExited += OnLeftWater;
DashTimer.Timeout += () =>
{
Velocity *= 0.6f;
Velocity = Velocity.LimitLength(WaterMaxSpeed);
var dot = _currentDirection.Normalized().Dot(Velocity.Normalized());
var slowdown = Mathf.Clamp(-dot + 0.2f, 0.0f, 0.5f);
Velocity *= 1f - slowdown;
DashHitbox.StopAttack();
};
}
@ -161,7 +165,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
WaterExitJump();
}
if (!DashTimer.IsStopped())
if (IsDashing)
{
if (!DashDirectionChangeTimer.IsStopped())
{
@ -203,9 +207,14 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
{
var walkInput = _currentDirection.X;
if (Mathf.Sign(velocity.X) != Mathf.Sign(walkInput))
{
velocity.X *= Mathf.Pow(GroundedSpeedStopDecay, deltaF);
}
else
{
// Speed too high, but the player wants to carry momentum
velocity.X *= Mathf.Pow(GroundedSpeedDecay, deltaF);
}
var targetVelX = Mathf.Sign(walkInput) * WalkMaxSpeed;
var isWalking = targetVelX != 0;
@ -231,7 +240,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
velocity.X = Mathf.Clamp(velocity.X, -AirMaxSpeed, AirMaxSpeed);
}
dragAmount = _currentDirection.IsZeroApprox() ? 0.015f : 0.009f;
dragAmount = _currentDirection.Normalized().Dot(Velocity.Normalized()) < 0.1f ? 0.015f : 0.002f;
}
// Move up while holding jump
@ -247,9 +256,10 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
if (IsDoingAnyJump) dragAmount = 0f;
velocity += Physics.DragForce(-velocity, dragAmount) * deltaF;
// Slow down descent while holding on to a wall
if (IsHoldingWall)
{
velocity.Y = Mathf.Min(velocity.Y, 5.0f);
if (velocity.Y >= 0f) velocity.Y = Mathf.MoveToward(velocity.Y * Mathf.Pow(0.0001f, deltaF), 0f, 750f * deltaF);
IsFacingRight = Mathf.Sign(GetWallNormal().X) > 0;
}
@ -299,6 +309,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
}
if (IsOnCeiling()) JumpTimer.Stop();
if (IsOnWall()) WallJumpAllowedTimer.Start();
}
public void OnEnteredWater(Node2D body)
@ -323,11 +334,20 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
private Vector2 FacingVector => IsFacingRight ? Vector2.Right : Vector2.Left;
private bool IsHoldingWall =>
!IsOnFloor()
&& IsOnWall()
&& Mathf.Sign(GetWallNormal().X) != Mathf.Sign(_currentDirection.X)
&& _currentDirection.X != 0;
private bool IsHoldingWall
{
get
{
var wallNormal = GetWallNormal();
return !IsOnFloor()
&& IsOnWall()
// player holding into the wall
&& Mathf.Sign(wallNormal.X) != Mathf.Sign(_currentDirection.X)
// wall isn't too bad of an overhang
&& wallNormal.Y <= 0.05f
&& _currentDirection.X != 0;
}
}
public void OnProcess(double delta)
{
@ -396,7 +416,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
return true;
case { Action: Action.Jump, IsPressed: true }
when IsOnWall():
when !WallJumpAllowedTimer.IsStopped():
WallJump();
return true;
@ -440,6 +460,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
private void WallJump()
{
AdjustFacing();
WallJumpAllowedTimer.Stop();
JumpAllowedTimer.Stop();
JumpTimer.Start();
@ -502,10 +523,9 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
DashDirectionChangeTimer.Start();
DashCooldownTimer.Start();
CreateTween()
.SetIgnoreTimeScale()
.TweenProperty(Engine.Singleton, "time_scale", 1.0f, 0.15f)
.From(0.01f)
.SetEase(Tween.EaseType.Out);
.TweenProperty(Engine.Singleton, "time_scale", 1.0f, 0.05f)
.From(0.01)
.SetEase(Tween.EaseType.InOut);
DashDirection = (_currentDirection.IsZeroApprox()
? FacingVector
: _currentDirection

View file

@ -3,9 +3,9 @@
[node name="AttackPlaceholder" type="Polygon2D" unique_id=2118857772]
color = Color(1, 1, 1, 0.54901963)
offset = Vector2(0, 16)
polygon = PackedVector2Array(-32, -48, 32, -48, 16, -16, -16, -16)
polygon = PackedVector2Array(-32, -64, 0, -80, 32, -64, 16, -16, -16, -16)
[node name="Area2D" type="Area2D" parent="." unique_id=578891655]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Area2D" unique_id=2127841935]
polygon = PackedVector2Array(-16, 0, -32, -32, 32, -32, 16, 0)
polygon = PackedVector2Array(-16, 0, -32, -48, 0, -64, 32, -48, 16, 0)

View file

@ -501,7 +501,13 @@ one_shot = true
[node name="JumpAllowedTimer" type="Timer" parent="." unique_id=705792352]
unique_name_in_owner = true
process_callback = 0
wait_time = 0.1
wait_time = 0.12
one_shot = true
[node name="WallJumpAllowedTimer" type="Timer" parent="." unique_id=2097477648]
unique_name_in_owner = true
process_callback = 0
wait_time = 0.073
one_shot = true
[node name="WaterJumpAllowedTimer" type="Timer" parent="." unique_id=1597932610]
@ -513,7 +519,7 @@ one_shot = true
[node name="DashTimer" type="Timer" parent="." unique_id=18391348]
unique_name_in_owner = true
process_callback = 0
wait_time = 0.2
wait_time = 0.12
one_shot = true
[node name="DashDirectionChangeTimer" type="Timer" parent="." unique_id=911466358]