// Use this for initialization void Start() { _ParticleSystem = GetComponent <ParticleSystem>(); G = WindGlobal.GetInstance(); }
private float Roll_change = 0.0f; // Z // Update Rotation Stuff (Returns Final Eulers) public void UpdateRotationEuler(ref Quadcopter.States State, ref Quadcopter.Settings Settings) { // Check Wind Direction if (WindGlobal.GetInstance() != null) { Vector3 WD = WindGlobal.GetInstance().GetWindDirection(); float WF = WindGlobal.GetInstance().GetWindStrength() * 0.1f; WF = Mathf.Pow(WF, 1.5f); if (WF != 0.0f) { // If up is aiming perpendicular to wind, no effect float WindEffect = Mathf.Abs(Vector3.Dot(WD, Quadcopter_Up)) * WF; _Rigidbody.gameObject.transform.RotateAround(Position, Vector3.right, WD.y * WindEffect); _Rigidbody.gameObject.transform.RotateAround(Position, Vector3.up, WD.x * WindEffect); _Rigidbody.gameObject.transform.RotateAround(Position, Vector3.forward, WD.z * WindEffect); //Vector3 TargetForward = WD; //// Check if direction is closer to backwards //if (Vector3.Distance(Quadcopter_Forward, WD) > Vector3.Distance(Quadcopter_Forward, -WD)) //{ // //TargetForward = -WD; //} // //// Slerp forward to target forward //_Rigidbody.gameObject.transform.up = Vector3.Slerp(Quadcopter_Up, TargetForward, 0.02f * WindEffect).normalized; } } // Update movement rotation if not broken if (!Settings._Broken) { // Update Ideal Eulers Pitch_Change = State.GetEulerChanges().x *Settings._PitchSpeed *((Settings._InversePitch) ? -1.0f : 1.0f); Yaw_Change = State.GetEulerChanges().y *Settings._YawSpeed *((Settings._InverseYaw) ? -1.0f : 1.0f); Roll_change = State.GetEulerChanges().z *Settings._RollSpeed *((Settings._InverseRoll) ? -1.0f : 1.0f); // Update Rotations _Rigidbody.gameObject.transform.RotateAround(Position, Quadcopter_Right, Pitch_Change); _Rigidbody.gameObject.transform.RotateAround(Position, Quadcopter_Up, Yaw_Change); _Rigidbody.gameObject.transform.RotateAround(Position, Quadcopter_Forward, Roll_change); // If rest state, fix orientation if controls aren't being touced if (Pitch_Change == 0.0f && Yaw_Change == 0.0f && Roll_change == 0.0f && Settings._ThrusterRest) { Vector3 Euler = _Rigidbody.gameObject.transform.eulerAngles; float spd = 0.06f; Euler.x = Mathfx.Clerp(Euler.x, 0.0f, spd); //Euler.y = Mathfx.Clerp(Euler.y, 0.0f, spd); Euler.z = Mathfx.Clerp(Euler.z, 0.0f, spd); _Rigidbody.gameObject.transform.eulerAngles = Euler; } } }
// Use this for initialization void Start() { if (_PauseObject != null) { _PauseMenu = _PauseObject.GetComponent <PauseMenu>(); } cameraOverride = FindObjectOfType <CameraShaderOverride>(); // Get all used rotors _RotorSetup = _Rotors.Setup(this); // Get Rigidbody _PhysicsSetup = _Physics.Setup(gameObject); // Fail Check if (FailCheck()) { return; } // Set Spawn _SpawnPosition = transform.position; // Set Camera Pitch Angle _Settings.UpdateCameraPitch(); // Set Camera FOV _Settings.UpdateFOV(); // Outputs Debug.Log("Total Rotors acquired: " + _Rotors.Amount()); // Setup Wind WindGlobal.GetInstance().Setup(this); // Setup Pause if (_PauseMenu != null) { _PauseMenu.Setup(this); } }
// Update Position public void UpdatePosition(ref Quadcopter.States State, ref Quadcopter.Settings Settings) { // Gravity Vector3 Gravity = new Vector3(0, Settings._Gravity * Settings._GravityModifier, 0); // Final Direction Vector3 FinalDirection = Gravity; // Float Thruster amount //float ThrusterAmount = State.GetThrusterUpwards(); float ThrusterAmount = State.GetThrusters(); // Inverse Setting if (Settings._InverseThrusters) { ThrusterAmount = ThrusterAmount * -1.0f; } // If broken, values are set to zero if (Settings._Broken) { ThrusterAmount = 0.0f; Speed_Ideal = 0.0f; } // Normal thruster checks else { // Rotor Speed Ideal if (ThrusterAmount >= 0.0f) { Speed_Ideal = ThrusterAmount * Settings._ThrusterSpeedUpwards * Settings._ThrusterSpeed; } else { Speed_Ideal = ThrusterAmount * Settings._ThrusterSpeedDownwards * Settings._ThrusterSpeed; } // If thrusters are being used if (ThrusterAmount > 0.0f) { // You move at least as the same speed as gravity Speed_Current = Mathf.Max(Speed_Current, -Gravity.y * 0.88f); } } // Rest State if thruster is at zero and not broken bool RestSate = (ThrusterAmount == 0.0f && Settings._ThrusterRest == true) && !Settings._Broken; // Thruster rest if (RestSate) { // Lerp speed to rest Speed_Current = Mathf.Lerp(Speed_Current, -Gravity.y, 0.07f); // If close enough, snap to gravity speed if (Mathf.Abs(Speed_Current + Gravity.y) < 0.01f) { Speed_Current = -Gravity.y; } } // Normal Transition else { // Lerp Speed to Ideal if (Speed_Current < Speed_Ideal) { // Going Up Speed_Current = Mathf.Lerp(Speed_Current, Speed_Ideal, Settings._ThrusterTransition_Upwards); } else { // Going Down Speed_Current = Mathf.Lerp(Speed_Current, Speed_Ideal, Settings._ThrusterTransition_Downwards); } } // Final Direction FinalDirection += Quadcopter_Up * Speed_Current; // If at rest, make sure y value clamps if close enough to zero if (RestSate && Mathf.Abs(FinalDirection.y) < 0.01f) { FinalDirection.y = 0.0f; } // Wind affects if (WindGlobal.GetInstance() != null) { // Wind affect velocity FinalDirection += (WindGlobal.GetInstance().GetWind()); } // Set Velocity SetVelocity(FinalDirection * Settings._GlobalSpeedModifier); }
private void UpdateSettings() { Quadcopter.Settings S = _Main._Settings; // Menu Left / Right int Direction = 0; if (Quadcopter.QuadcopterControls.MenuLeft()) { Direction -= 1; } if (Quadcopter.QuadcopterControls.MenuRight()) { Direction += 1; } Left = (Direction < 0); Right = (Direction > 0); string text = ""; switch (_PageIndex) { case 0: { float Pitch = S._CameraPitchAngle; float FOV = S._CameraFOV; WindControl Wind = WindGlobal.GetInstance()._Control; float GlobalSpeed = S._GlobalSpeedModifier; bool RestMode = S._ThrusterRest; AddText(ref text, Pitch, 1, true); AddText(ref text, FOV, 1, true); AddText(ref text, Wind.ToString()); AddText(ref text, GlobalSpeed); AddText(ref text, RestMode); // Controls switch (_SelectionIndex) { case 0: UpdateValue(ref S._CameraPitchAngle, 1.0f, -45.0f, 45.0f); S.UpdateCameraPitch(); break; case 1: UpdateValue(ref S._CameraFOV, 1.0f, 90.0f, 170.0f); S.UpdateFOV(); break; case 2: if (Left) { WindGlobal.GetInstance()._Control -= 1; } if (Right) { WindGlobal.GetInstance()._Control += 1; } // Clamp if ((int)WindGlobal.GetInstance()._Control >= WindGlobal.WindControlTotal) { WindGlobal.GetInstance()._Control = WindControl.NONE; } if ((int)WindGlobal.GetInstance()._Control < 0) { WindGlobal.GetInstance()._Control = WindControl.CONSISTENT_CALM; } break; case 3: UpdateValue(ref S._GlobalSpeedModifier, 0.01f, 0.0f, 1.0f); break; case 4: UpdateValue(ref S._ThrusterRest); break; } } break; case 1: { float T_S = S._ThrusterSpeed; Quadcopter.AnalogPossibilities T_C = S._ThrusterControl; bool T_I = S._InverseThrusters; AddText(ref text, T_S, 2); AddText(ref text, T_C.ToString()); AddText(ref text, T_I); switch (_SelectionIndex) { case 0: UpdateValue(ref S._ThrusterSpeed, 0.02f, 0.0f, 5.0f); break; case 1: break; case 2: UpdateValue(ref S._InverseThrusters); break; } } break; case 2: { float Pitch_S = S._PitchSpeed; float Yaw_S = S._YawSpeed; float Roll_S = S._RollSpeed; Quadcopter.AnalogPossibilities Pitch_C = S._YawControl; Quadcopter.AnalogPossibilities Yaw_C = S._YawControl; Quadcopter.AnalogPossibilities Roll_C = S._YawControl; bool Pitch_I = S._InversePitch; bool Yaw_I = S._InverseYaw; bool Roll_I = S._InverseRoll; AddText(ref text, Pitch_S, 2); AddText(ref text, Yaw_S, 2); AddText(ref text, Roll_S, 2); AddText(ref text, Pitch_C.ToString()); AddText(ref text, Yaw_C.ToString()); AddText(ref text, Roll_C.ToString()); AddText(ref text, Pitch_I); AddText(ref text, Yaw_I); AddText(ref text, Roll_I); switch (_SelectionIndex) { case 0: UpdateValue(ref S._PitchSpeed, 0.02f, 0.0f, 5.0f); break; case 1: UpdateValue(ref S._YawSpeed, 0.02f, 0.0f, 5.0f); break; case 2: UpdateValue(ref S._RollSpeed, 0.02f, 0.0f, 5.0f); break; case 6: UpdateValue(ref S._InversePitch); break; case 7: UpdateValue(ref S._InverseYaw); break; case 8: UpdateValue(ref S._InverseRoll); break; } } break; } _SettingsData.text = text; }