AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
AC_Airplane_ControlSurface.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using Commons;
5 
6 namespace AirControl
7 { public enum ControlSurfaceType{
8  Rudder,
9  Elevator,
10  Flaps,
11  Alerons
12  }
16  public class AC_Airplane_ControlSurface : MonoBehaviour
17 {
18  #region Variables
19  [Header("Control surface Properties")]
20  public ControlSurfaceType surfacetype = ControlSurfaceType.Rudder;
21  private float maxAngle;
22  public Vector3 axis = Vector3.right;
23  public Transform controlSurfaceGraphic;
24  // smoothly rotate
25  private float smoothSpeed;
26  private float wantedAngle;
27  #endregion
28 
29  #region Builtin Methods
30 
31  void Start(){
32  maxAngle = (float)CommonFunctions.airplanePreset[CommonFunctions.activeAirplane+"/maxAngle"];
33  smoothSpeed= (float)CommonFunctions.airplanePreset[CommonFunctions.activeAirplane+"/smoothSpeed"];
34 
35  }
36 
37  // Update is called once per frame
38  void Update()
39  {
40  if(controlSurfaceGraphic){
41  // rotate the control surface
42  Vector3 effectiveRotationAxis = axis*wantedAngle;
43  controlSurfaceGraphic.localRotation = Quaternion.Slerp(controlSurfaceGraphic.localRotation, Quaternion.Euler(effectiveRotationAxis), Time.deltaTime*smoothSpeed);
44  }
45  }
46  #endregion
47 
48  #region Custom Methods
54  {
55  float inputValue = 0f;
56  switch(surfacetype)
57  {
58  case ControlSurfaceType.Rudder:
59  inputValue = input.Yaw;
60  break;
61  case ControlSurfaceType.Elevator:
62  inputValue = input.Pitch;
63  break;
64  case ControlSurfaceType.Flaps:
65  inputValue = input.Flaps;
66  break;
67  case ControlSurfaceType.Alerons:
68  inputValue = input.Roll;
69  break;
70  default:
71  // Throw error here
72  break;
73  }
74  wantedAngle = maxAngle*inputValue;
75  }
76  #endregion
77 }
78 
79 }
AirControl.AC_BaseAirplane_Input
Base class to listen for keyboard Inputs
Definition: AC_BaseAirplane_Input.cs:12
AirControl.AC_Airplane_ControlSurface.HandleControlSurface
void HandleControlSurface(AC_BaseAirplane_Input input)
Main function to handle Control Surface
Definition: AC_Airplane_ControlSurface.cs:53
AirControl
Definition: AirplaneSelector.cs:8
AirControl.AC_Airplane_ControlSurface
Handle control surfaces including Rudder, Elevator, Flaps,and Alerons
Definition: AC_Airplane_ControlSurface.cs:16
Commons
Definition: AirplaneProperties.cs:14