-feat: include rotational velocity in flight assist (now more newtonian). -fix: lasers actually despawn when they hit the border

This commit is contained in:
rsxri 2025-04-21 20:03:51 +01:00
parent cf500dc06e
commit fbca225784
2 changed files with 15 additions and 3 deletions

View file

@ -10,7 +10,7 @@ height = 56.0
[node name="Laser" type="Area2D"]
scale = Vector2(0.6, 0.6)
collision_layer = 8
collision_mask = 5
collision_mask = 13
script = ExtResource("1_ctmji")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]

View file

@ -17,6 +17,9 @@ public partial class player : ship // Inherits from base ship class
[Export]
public float FlightAssistValue { get; set; } = 2.5f;
private float _angularVelocity;
private float _angularAccel = 0.3f;
private void GetInput()
{
@ -26,6 +29,15 @@ public partial class player : ship // Inherits from base ship class
// Movement, could probably move into its own methods instead of GetInput()
RotationDirection = (int)Input.GetAxis("left", "right");
_angularVelocity += RotationDirection * _angularAccel;
_angularVelocity = Mathf.Clamp(_angularVelocity, -RotationSpeed, RotationSpeed);
if (RotationDirection == 0 && FlightAssistValue > 0f)
{
_angularVelocity = Mathf.MoveToward(_angularVelocity, 0f, FlightAssistValue);
}
//GD.Print(RotationDirection);
Velocity += (Transform.X * Input.GetAxis("strafe_left", "strafe_right") * StrafeSpeed) + (Transform.Y * Input.GetAxis("up", "down") * MainSpeed);
Velocity = Velocity.LimitLength(MaxSpeed);
@ -100,7 +112,7 @@ public partial class player : ship // Inherits from base ship class
public override void _PhysicsProcess(double delta)
{ // every frame
GetInput();
Rotation += RotationDirection * RotationSpeed * (float)delta;
Rotation += _angularVelocity * (float)delta;
Velocity.LimitLength(MaxSpeed);
//GD.Print(MainSpeed);