From fbca225784d791ce98ecbdc241a4a56688b8c509 Mon Sep 17 00:00:00 2001 From: rsxri Date: Mon, 21 Apr 2025 20:03:51 +0100 Subject: [PATCH] -feat: include rotational velocity in flight assist (now more newtonian). -fix: lasers actually despawn when they hit the border --- MB_FYP/scenes/laser.tscn | 2 +- MB_FYP/script/player.cs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/MB_FYP/scenes/laser.tscn b/MB_FYP/scenes/laser.tscn index df7a0ca..5e9be1b 100644 --- a/MB_FYP/scenes/laser.tscn +++ b/MB_FYP/scenes/laser.tscn @@ -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="."] diff --git a/MB_FYP/script/player.cs b/MB_FYP/script/player.cs index 05e0c61..3bfde99 100644 --- a/MB_FYP/script/player.cs +++ b/MB_FYP/script/player.cs @@ -17,15 +17,27 @@ 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() { /*LookAt(GetGlobalMousePosition()); //used for mouse-based rotation and movement Velocity = Transform.X * Input.GetAxis("down", "up") * Speed; */ - + // 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);