Initial commit

This commit is contained in:
qwsdcvghyu89
2026-06-05 22:43:54 +10:00
commit 42455a84d6
22 changed files with 791 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
using Godot;
using System;
using System.Diagnostics;
public partial class PlayerPhysicsController : CharacterBody2D {
[Export]
public float FloatingMovePenalty { get; set; } = 0.1f;
[Export]
public float FloatingJumpPenalty { get; set; } = 0.1f;
[Export]
public float JumpStrengthDecay { get; set; } = 2;
[Export]
public float MovementDecay { get; set; } = 2;
[Export]
public float MovementScale { get; set; } = 10;
[Export]
public float JumpScale { get; set; } = 12;
[Export]
public Label DebugTextLabel { get; set; }
[Export]
public float Gravity { get; set; } = 9.8f;
private float _timeInFlight = 0;
public override void _PhysicsProcess(double delta) {
var xAxis = Input.GetAxis("move_left", "move_right") * MovementScale;
var yAxis = Input.GetAxis("look_up", "look_down");
var jumpStrength = -Input.GetActionStrength("jump") * JumpScale;
var grounded = this.IsOnFloor();
if (!grounded) {
xAxis *= FloatingMovePenalty;
jumpStrength *= FloatingJumpPenalty;
}
if (grounded && jumpStrength < 0)
_timeInFlight = 0;
jumpStrength *= Mathf.Exp(-JumpStrengthDecay * _timeInFlight);
xAxis *= Mathf.Exp(-MovementDecay * Mathf.Abs(Velocity.X));
var moveVector = new Vector2(xAxis, Gravity + jumpStrength);
DebugTextLabel.Text = $"grounded: {grounded}\nmv: {moveVector}\njumpStrength: {jumpStrength}\ntimeInFlight: {_timeInFlight}";
Velocity += moveVector;
MoveAndSlide();
if (!grounded)
_timeInFlight += (float)delta;
base._Process(delta);
}
}