1 using System.Collections;
2 using System.Collections.Generic;
6 using JetBrains.Annotations;
8 using UnityEngine.TextCore.LowLevel;
16 [RequireComponent(typeof(AC_Airplane_Propeller))]
17 [RequireComponent(typeof(AC_Airplane_Fuel))]
18 [RequireComponent(typeof(AC_Airplane_Audio))]
19 [RequireComponent(typeof(AC_BaseAirplane_Input))]
20 [RequireComponent(typeof(AC_XboxAirplane_Input))]
21 [RequireComponent(typeof(AC_Airplane_Audio))]
25 [Header(
"Engine Properties")]
26 public float maxForce = 3000f;
27 public float maxRPM = 3500f;
29 public AnimationCurve powerCurve = AnimationCurve.Linear(0f, 0f, 1f, 1f);
30 public AnimationCurve liftOff = AnimationCurve.Linear(0f, 0f, 1000f, 1000f);
32 [Header(
"Propellers")]
35 private float shutOffSpeed = 2f;
36 private bool isShutOff =
false;
37 private float lastThrottleValue;
38 private float finalShutoffThrottleValue;
39 private Vector3 rotationDelta;
40 private Vector3 rotationLast;
41 private float propellerSpan;
49 public bool ShutEngineOff
51 set{isShutOff = value;}
54 private float currentRPM;
55 public float CurrentRPM
57 get{
return currentRPM;}
62 private const float engineEfficiency = 0.6f;
63 private const float airDensity = 0.07967f;
66 #region BuiltIn Methods
73 propellerSpan = (float)CommonFunctions.airplanePreset[CommonFunctions.ActiveAirplane+
"/propellarSpan"];
74 maxRPM = (
float)CommonFunctions.airplanePreset[CommonFunctions.ActiveAirplane+
"/maxRPM"];
75 shutOffSpeed = (float)CommonFunctions.airplanePreset[CommonFunctions.ActiveAirplane+
"/shutOffSpeed"];
78 fuel = GetComponent<AC_Airplane_Fuel>();
89 maxForce = engineEfficiency*airDensity* (float)Math.Pow(propellerSpan,4)* (float)Math.Pow(rotationDelta.magnitude,2);
93 #region Custom Methods
95 public void getAngularVelocityPro()
97 rotationDelta = propeller.transform.eulerAngles - rotationLast;
98 rotationLast = propeller.transform.eulerAngles;
113 float finalThrottle = Mathf.Clamp01(throttle);
115 getAngularVelocityPro();
119 finalThrottle = powerCurve.Evaluate(finalThrottle);
121 lastThrottleValue = finalThrottle;
125 lastThrottleValue -= Time.deltaTime * shutOffSpeed;
126 lastThrottleValue = Mathf.Clamp01(lastThrottleValue);
127 finalThrottle = powerCurve.Evaluate(lastThrottleValue);
132 currentRPM = finalThrottle * maxRPM;
135 propeller.HandlePropeller(currentRPM);
140 HandleFuel(finalThrottle);
144 float finalPower = finalThrottle * maxForce;
145 Vector3 finalForce = transform.forward * finalPower;
150 StaticOutputSchema.MaxPower = maxForce;
151 StaticOutputSchema.CurrentPower = finalPower;
152 StaticOutputSchema.MaxRPM = maxRPM;
153 StaticOutputSchema.CurrentRPM = currentRPM;
163 void HandleFuel(
float throttleValue)
169 if(fuel.CurrentFuel <= 0f)