From 4e344cc02ddfd29f9c9aa3e1936496e390797b89 Mon Sep 17 00:00:00 2001 From: qwsdcvghyu89 <61093706+qwsdcvghyu89@users.noreply.github.com> Date: Sun, 14 Jun 2026 20:56:06 +1000 Subject: [PATCH] Fixed run affecting air speed bug; fixed auto zeroing of velocities bug. --- global.json | 7 +++++++ objects/scenes/demo/demo.tscn | 4 ++-- src/components/PlayerPhysicsController.cs | 18 +++++++++--------- src/library/LevelPattern.cs | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 0000000..2d23ad3 --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "11.0.100-preview.5.26302.115", + "allowPrerelease": true, + "rollForward": "latestPatch" + } +} diff --git a/objects/scenes/demo/demo.tscn b/objects/scenes/demo/demo.tscn index 9eb87ca..854b962 100644 --- a/objects/scenes/demo/demo.tscn +++ b/objects/scenes/demo/demo.tscn @@ -216,7 +216,7 @@ script = ExtResource("2_oekxy") WalkAcceleration = 30.0 StoppingDeceleration = 50.0 CancellationAcceleration = 50.0 -AirAcceleration = 9.0 +AirAcceleration = 5.0 MaxFallSpeed = 50.0 MaxRiseSpeed = 50.0 MaxRunSpeed = 12.0 @@ -237,7 +237,7 @@ sprite_frames = ExtResource("2_wq5k4") animation = &"walk" [node name="Camera2D" type="Camera2D" parent="Player/CharacterBody2D" unique_id=1068565115] -zoom = Vector2(5, 5) +zoom = Vector2(2, 2) [node name="Label" type="Label" parent="Player/CharacterBody2D" unique_id=436935745] offset_left = 22.0 diff --git a/src/components/PlayerPhysicsController.cs b/src/components/PlayerPhysicsController.cs index 1d8a582..5376b16 100644 --- a/src/components/PlayerPhysicsController.cs +++ b/src/components/PlayerPhysicsController.cs @@ -35,6 +35,8 @@ public partial class PlayerPhysicsController : CharacterBody2D { private float MaxRunSpeed { get; set; } = 16f; [Export] private float MaxWalkSpeed { get; set; } = 8f; + [Export] + private float MaxAirSpeed { get; set; } = 16f; [ExportCategory("Objects")] [Export] @@ -65,7 +67,7 @@ public partial class PlayerPhysicsController : CharacterBody2D { [Export] public float Deadzone { get; set; } = 0.1f; - + public float GetMinAccel(float delta) => CancellationAcceleration * delta; private float _lv = 0.0f; @@ -125,8 +127,6 @@ public partial class PlayerPhysicsController : CharacterBody2D { float velx = (Velocity.X / UnitToPx); float vely = (Velocity.Y / UnitToPx) + Gravity * (float)delta; - if (Mathf.Abs(velx) < 0.1) velx = 0; - var grounded = this.IsOnFloor(); var coyoteGrounded = _timeOffGround < CoyoteTiming; if (grounded || coyoteGrounded) { @@ -206,21 +206,21 @@ public partial class PlayerPhysicsController : CharacterBody2D { else velx += autostop; } - var maxXSpeed = Input.IsActionPressed("run") ? MaxRunSpeed : MaxWalkSpeed; + 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) velx = 0; + if (Mathf.Abs(xcancel) + 0.1 > absvelx && xcancel != 0) velx = 0; else velx += xcancel; - if (Mathf.Abs(ycancel) + 0.1 > absvely) vely = 0; - else vely += ycancel; + if (Mathf.Abs(ycancel) + 0.1 > absvely && ycancel != 0) vely = 0; + else vely += ycancel; DebugTextLabel.Text = $"grounded: {grounded}\n" + - $"vely: {vely}\n" + - $"velx: {velx}\n" + + $"vely: (v+{ycancel}=){vely}\n" + + $"velx: (v+{xcancel}=){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); diff --git a/src/library/LevelPattern.cs b/src/library/LevelPattern.cs index 25a5985..fb02b8f 100644 --- a/src/library/LevelPattern.cs +++ b/src/library/LevelPattern.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; #nullable enable + public class LevelPattern { public TileMapPattern Level { get; }