From 80a6d55305e8a35453a4ef2c1fced6338c15822d Mon Sep 17 00:00:00 2001 From: Titan Yuan Date: Fri, 11 Oct 2024 17:53:15 -0700 Subject: [PATCH] Remove compensation for gravity (#13) --- Assets/Scripts/Agent.cs | 8 +------- Assets/Scripts/Interceptor.cs | 4 ++-- Assets/Scripts/Threats/FixedWingThreat.cs | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/Agent.cs b/Assets/Scripts/Agent.cs index df20d406..0771c7f6 100644 --- a/Assets/Scripts/Agent.cs +++ b/Assets/Scripts/Agent.cs @@ -249,14 +249,8 @@ protected virtual void AlignWithVelocity() { } } - protected Vector3 CalculateAcceleration(Vector3 accelerationInput, - bool compensateForGravity = false) { + protected Vector3 CalculateAcceleration(Vector3 accelerationInput) { Vector3 gravity = Physics.gravity; - if (compensateForGravity) { - Vector3 gravityProjection = CalculateGravityProjectionOnPitchAndYaw(); - accelerationInput -= gravityProjection; - } - float airDrag = CalculateDrag(); float liftInducedDrag = CalculateLiftInducedDrag(accelerationInput + gravity); float dragAcceleration = -(airDrag + liftInducedDrag); diff --git a/Assets/Scripts/Interceptor.cs b/Assets/Scripts/Interceptor.cs index 11d75add..fcb653ca 100644 --- a/Assets/Scripts/Interceptor.cs +++ b/Assets/Scripts/Interceptor.cs @@ -63,7 +63,7 @@ protected override void UpdateBoost(double deltaTime) { Vector3 accelerationInput = boostAcceleration * rollAxis; // Calculate the total acceleration - Vector3 acceleration = CalculateAcceleration(accelerationInput, compensateForGravity: false); + Vector3 acceleration = CalculateAcceleration(accelerationInput); // Apply the acceleration force GetComponent().AddForce(acceleration, ForceMode.Acceleration); @@ -97,7 +97,7 @@ protected override void UpdateMidCourse(double deltaTime) { } // Calculate and set the total acceleration - Vector3 acceleration = CalculateAcceleration(accelerationInput, compensateForGravity: true); + Vector3 acceleration = CalculateAcceleration(accelerationInput); GetComponent().AddForce(acceleration, ForceMode.Acceleration); } diff --git a/Assets/Scripts/Threats/FixedWingThreat.cs b/Assets/Scripts/Threats/FixedWingThreat.cs index 95f03282..fb60e1a7 100644 --- a/Assets/Scripts/Threats/FixedWingThreat.cs +++ b/Assets/Scripts/Threats/FixedWingThreat.cs @@ -52,7 +52,7 @@ protected override void UpdateMidCourse(double deltaTime) { } // Calculate and set the total acceleration - Vector3 acceleration = CalculateAcceleration(accelerationInput, compensateForGravity: true); + Vector3 acceleration = CalculateAcceleration(accelerationInput); GetComponent().AddForce(acceleration, ForceMode.Acceleration); }