Fixed cancellation logic; added double jump max fall speed property.
Release / Export Game (push) Successful in 2m3s
Release / Export Game (push) Successful in 2m3s
This commit is contained in:
@@ -37,6 +37,8 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
||||
private float MaxWalkSpeed { get; set; } = 8f;
|
||||
[Export]
|
||||
private float MaxAirSpeed { get; set; } = 16f;
|
||||
[Export]
|
||||
private float MaxDoubleJumpFallSpeed { get; set; } = 1f;
|
||||
|
||||
[ExportCategory("Objects")]
|
||||
[Export]
|
||||
@@ -193,7 +195,7 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed("jump") && Mathf.Abs(vely) < 2) {
|
||||
if (Input.IsActionJustPressed("jump") && Mathf.Abs(vely) < MaxDoubleJumpFallSpeed) {
|
||||
vely = -_lv;
|
||||
}
|
||||
|
||||
@@ -209,18 +211,15 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
||||
var maxXSpeed = grounded ? Input.IsActionPressed("run") ? MaxRunSpeed : MaxWalkSpeed : MaxAirSpeed;
|
||||
var maxYSpeed = vely > 0 ? MaxFallSpeed : MaxRiseSpeed;
|
||||
var (absvelx, absvely) = (Mathf.Abs(velx), Mathf.Abs(vely));
|
||||
float xcancel = 0, ycancel = 0;
|
||||
if (absvelx > maxXSpeed) xcancel = -Math.Sign(velx) * CancellationAcceleration * (float)delta;
|
||||
if (absvely > maxYSpeed) ycancel = -Math.Sign(vely) * CancellationAcceleration * (float)delta;
|
||||
if (Mathf.Abs(xcancel) + 0.1 > absvelx && xcancel != 0) velx = 0;
|
||||
else velx += xcancel;
|
||||
if (Mathf.Abs(ycancel) + 0.1 > absvely && ycancel != 0) vely = 0;
|
||||
else vely += ycancel;
|
||||
if (absvelx > maxXSpeed)
|
||||
velx = Mathf.Sign(velx) * Mathf.Max(absvelx - CancellationAcceleration * (float)delta, maxXSpeed);
|
||||
if (absvely > maxYSpeed)
|
||||
vely = Mathf.Sign(vely) * Mathf.Max(absvely - CancellationAcceleration * (float)delta, maxYSpeed);
|
||||
|
||||
DebugTextLabel.Text =
|
||||
$"grounded: {grounded}\n" +
|
||||
$"vely: (v+{ycancel}=){vely}\n" +
|
||||
$"velx: (v+{xcancel}=){velx}\n" +
|
||||
$"vely: {vely}\n" +
|
||||
$"velx: {velx}\n" +
|
||||
$"lv : {_lv:F2} or {_lv/(float)delta:F2}\n" +
|
||||
$"lcrc : {Predictor.AnyHit(PredictiveCollisions.Location.BottomLeft)}/{Predictor.AnyHit(PredictiveCollisions.Location.BottomRight)}";
|
||||
// Force = new Vector2(0, forcey);
|
||||
|
||||
Reference in New Issue
Block a user