Beispiel #1
0
        public void HandleControlSurface(IP_BaseAirplane_Input input)
        {
            float inputValue = 0f;

            switch (type)
            {
            case ControlSurfaceType.Rudder:
                inputValue = input.Yaw;
                break;

            case ControlSurfaceType.Elevator:
                inputValue = input.Pitch;
                break;

            case ControlSurfaceType.Flap:
                inputValue = input.Flaps;
                break;

            case ControlSurfaceType.Aileron:
                inputValue = input.Roll;
                break;

            default:
                break;
            }

            wantedAngle = maxAngle * inputValue;
        }
Beispiel #2
0
        public void InitCharacteristics(Rigidbody curRB, IP_BaseAirplane_Input curInput)
        {
            //Basic Initialization
            input            = curInput;
            rb               = curRB;
            startDrag        = rb.drag;
            startAngularDrag = rb.angularDrag;

            //Find the max Meters Per Second
            maxMPS = maxMPH / mpsToMph;
        }
Beispiel #3
0
        public void HandleWheel(IP_BaseAirplane_Input input)
        {
            if (WheelCol)
            {
                //Place the Wheel in the correct position
                WheelCol.GetWorldPose(out worldPos, out worldRot);
                if (wheelGraphic)
                {
                    wheelGraphic.rotation = worldRot;
                    wheelGraphic.position = worldPos;
                }

                //Handle the Braking of the Wheel
                if (isBraking)
                {
                    if (input.Brake > 0.1f)
                    {
                        finalBrakeForce      = Mathf.Lerp(finalBrakeForce, input.Brake * brakePower, Time.deltaTime);
                        WheelCol.brakeTorque = finalBrakeForce;
                    }
                    else
                    {
                        finalBrakeForce      = 0f;
                        WheelCol.brakeTorque = 0f;
                        WheelCol.motorTorque = 0.000000000001f;
                    }
                }

                //Handle steering of the wheel
                if (isSteering)
                {
                    finalSteerAngle     = Mathf.Lerp(finalSteerAngle, -input.Yaw * steerAngle, Time.deltaTime * steerSmoothSpeed);
                    WheelCol.steerAngle = finalSteerAngle;
                }

                //Check to see if the wheel is grounded
                isGrounded = WheelCol.isGrounded;
            }
        }
Beispiel #4
0
        public static void BuildDefaultAirplane(string aName)
        {
            // Create the root GO
            GameObject rootGO = new GameObject(aName, typeof(IP_Airplane_Controller), typeof(IP_BaseAirplane_Input));

            // Create the Center of Gravity
            GameObject cogGO = new GameObject("COG");

            cogGO.transform.SetParent(rootGO.transform, false);

            // Create the Base Components or Find them
            IP_BaseAirplane_Input       input           = rootGO.GetComponent <IP_BaseAirplane_Input>();
            IP_Airplane_Controller      controller      = rootGO.GetComponent <IP_Airplane_Controller>();
            IP_Airplane_Characteristics characteristics = rootGO.GetComponent <IP_Airplane_Characteristics>();

            //Setup the Airplane
            if (controller)
            {
                // Assigning core Components
                controller.input           = input;
                controller.characteristics = characteristics;
                controller.centerOfGravity = cogGO.transform;

                // Create Structure
                GameObject graphicsGrp       = new GameObject("Graphics_GRP");
                GameObject collisionGrp      = new GameObject("Collision_GRP");
                GameObject controlSurfaceGrp = new GameObject("ControlSurfaces_GRP");
                GameObject audioGrp          = new GameObject("Audio_GRP", typeof(IP_Airplane_Audio));

                graphicsGrp.transform.SetParent(rootGO.transform, false);
                collisionGrp.transform.SetParent(rootGO.transform, false);
                controlSurfaceGrp.transform.SetParent(rootGO.transform, false);
                audioGrp.transform.SetParent(rootGO.transform, false);

                // Create GEO Structure
                GameObject controlSurfaceGeo = new GameObject("ControlSurfaces_GEO");
                GameObject propellersGeo     = new GameObject("Propellers_GEO", typeof(IP_Airplane_Propeller));
                GameObject wheelsGeo         = new GameObject("Wheels_GEO");

                controlSurfaceGeo.transform.SetParent(graphicsGrp.transform, false);
                propellersGeo.transform.SetParent(graphicsGrp.transform, false);
                wheelsGeo.transform.SetParent(graphicsGrp.transform, false);

                // Create ControlSurfaces_GEO children
                GameObject elevatorGeo = new GameObject("Elevator_GEO");
                GameObject rudderGeo   = new GameObject("Rudder_GEO");
                GameObject laileronGeo = new GameObject("L_Aileron_GEO");
                GameObject raileronGeo = new GameObject("R_Aileron_GEO");
                GameObject lflapGeo    = new GameObject("L_Flap_GEO");
                GameObject rflapGeo    = new GameObject("R_Flap_GEO");

                elevatorGeo.transform.SetParent(controlSurfaceGeo.transform, false);
                rudderGeo.transform.SetParent(controlSurfaceGeo.transform, false);
                laileronGeo.transform.SetParent(controlSurfaceGeo.transform, false);
                raileronGeo.transform.SetParent(controlSurfaceGeo.transform, false);
                lflapGeo.transform.SetParent(controlSurfaceGeo.transform, false);
                rflapGeo.transform.SetParent(controlSurfaceGeo.transform, false);

                // Create ControlSurfaces_GRP children
                GameObject elevatorGrp = new GameObject("Elevator", typeof(IP_Airplane_ControlSurface));
                GameObject rudderGrp   = new GameObject("Rudder", typeof(IP_Airplane_ControlSurface));
                GameObject laileronGrp = new GameObject("L_Aileron", typeof(IP_Airplane_ControlSurface));
                GameObject raileronGrp = new GameObject("R_Aileron", typeof(IP_Airplane_ControlSurface));
                GameObject lflapGrp    = new GameObject("L_Flap", typeof(IP_Airplane_ControlSurface));
                GameObject rflapGrp    = new GameObject("R_Flap", typeof(IP_Airplane_ControlSurface));

                elevatorGrp.transform.SetParent(controlSurfaceGrp.transform, false);
                rudderGrp.transform.SetParent(controlSurfaceGrp.transform, false);
                laileronGrp.transform.SetParent(controlSurfaceGrp.transform, false);
                raileronGrp.transform.SetParent(controlSurfaceGrp.transform, false);
                lflapGrp.transform.SetParent(controlSurfaceGrp.transform, false);
                rflapGrp.transform.SetParent(controlSurfaceGrp.transform, false);

                // Create Collision_GRP children
                GameObject bodyFrontCol = new GameObject("Body_Front_COL");
                GameObject bodyBackCol  = new GameObject("Body_Back_COL");
                GameObject lwingCol     = new GameObject("L_Wing_COL");
                GameObject rwingCol     = new GameObject("R_Wing_COL");
                GameObject vertfinCol   = new GameObject("Vertical_Fin_COL");
                GameObject horfinCol    = new GameObject("Horizontal_Fin_COL");
                GameObject rwheelCol    = new GameObject("R_Wheel_COL");
                GameObject lwheelCol    = new GameObject("L_Wheel_COL");
                GameObject backwheelCol = new GameObject("Back_Wheel_COL");

                bodyFrontCol.transform.SetParent(collisionGrp.transform, false);
                bodyBackCol.transform.SetParent(collisionGrp.transform, false);
                lwingCol.transform.SetParent(collisionGrp.transform, false);
                rwingCol.transform.SetParent(collisionGrp.transform, false);
                vertfinCol.transform.SetParent(collisionGrp.transform, false);
                horfinCol.transform.SetParent(collisionGrp.transform, false);
                rwheelCol.transform.SetParent(collisionGrp.transform, false);
                lwheelCol.transform.SetParent(collisionGrp.transform, false);
                backwheelCol.transform.SetParent(collisionGrp.transform, false);

                // Create Follow_Camera, Cockpit_Camera and Camera_Controller
                GameObject followCamera       = new GameObject("Follow_Camera", typeof(Camera), typeof(IP_Airplane_Camera));
                GameObject cockpitCamera      = new GameObject("Cockpit_Camera", typeof(Camera));
                GameObject cameraControllerGO = new GameObject("Camera_Controller", typeof(IP_AirplaneCamera_Controller));
                IP_AirplaneCamera_Controller cameraController = cameraControllerGO.GetComponent <IP_AirplaneCamera_Controller>();
                cameraController.input = input;

                followCamera.transform.SetParent(rootGO.transform, false);
                cockpitCamera.transform.SetParent(rootGO.transform, false);
                cameraControllerGO.transform.SetParent(rootGO.transform, false);

                // Create Audio_GRP children
                GameObject idleAudio         = new GameObject("Idle_Audio", typeof(AudioSource));
                GameObject fullthrottleAudio = new GameObject("FullThrottle_Audio", typeof(AudioSource));

                idleAudio.transform.SetParent(audioGrp.transform, false);
                fullthrottleAudio.transform.SetParent(audioGrp.transform, false);

                //Create First Engine
                GameObject         engineGO = new GameObject("Engine", typeof(IP_Airplane_Engine));
                IP_Airplane_Engine engine   = engineGO.GetComponent <IP_Airplane_Engine>();
                controller.engines.Add(engine);
                engineGO.transform.SetParent(rootGO.transform, false);

                //Create the base Airplane
                GameObject defaultAirplane = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Military Aircraft Pack/A10/A10.fbx", typeof(GameObject));
                if (defaultAirplane)
                {
                    GameObject.Instantiate(defaultAirplane, graphicsGrp.transform);
                }
            }

            //Select the Airplane Setup
            Selection.activeGameObject = rootGO;
        }
Beispiel #5
0
        // Use this for initialization
        void Start()
        {
            var foundControllers     = FindObjectsOfType <IP_Airplane_Controller>();
            var foundEngines         = FindObjectsOfType <IP_Airplane_Engine>();
            var foundInputs          = FindObjectsOfType <IP_BaseAirplane_Input>();
            var foundFuels           = FindObjectsOfType <IP_Airplane_Fuel>();
            var foundCharacteristics = FindObjectsOfType <IP_Airplane_Characteristics>();

            Debug.Log(foundControllers + " : " + foundControllers.Length);

            if (foundControllers.Length == 1)
            {
                targetController = foundControllers[0];
            }
            if (foundEngines.Length == 1)
            {
                targetEngine = foundEngines[0];
            }
            if (foundInputs.Length == 1)
            {
                targetInput = foundInputs[0];
            }
            if (foundFuels.Length == 1)
            {
                targetFuel = foundFuels[0];
            }
            if (foundCharacteristics.Length == 1)
            {
                targetCharacteristics = foundCharacteristics[0];
            }
            // Altimeter
            IP_Airplane_Altimeter altimeter = GameObject.FindObjectOfType <IP_Airplane_Altimeter>();

            if (altimeter)
            {
                altimeter.airplane = targetController;
            }

            // Tachometer
            IP_Airplane_Tachometer tachometer = GameObject.FindObjectOfType <IP_Airplane_Tachometer>();

            if (tachometer)
            {
                tachometer.engine = targetEngine;
            }

            // Fuel_Gauge
            IP_Airplane_FuelGauge fuelGauge = GameObject.FindObjectOfType <IP_Airplane_FuelGauge>();

            if (fuelGauge)
            {
                fuelGauge.fuel = targetFuel;
            }

            // Throttle_Lever
            IP_Airplane_ThrottleLever throttleLever = GameObject.FindObjectOfType <IP_Airplane_ThrottleLever>();

            if (throttleLever)
            {
                throttleLever.input = targetInput;
            }

            // Flap_Lever
            IP_Airplane_FlapLever flapLever = GameObject.FindObjectOfType <IP_Airplane_FlapLever>();

            if (flapLever)
            {
                flapLever.input = targetInput;
            }

            // Airspeed
            IP_Airplane_Airspeed airspeed = GameObject.FindObjectOfType <IP_Airplane_Airspeed>();

            if (airspeed)
            {
                airspeed.characteristics = targetCharacteristics;
            }

            // Track Manager
            var trackManager = FindObjectOfType <IP_Track_Manager>();

            if (trackManager)
            {
                trackManager.airplaneController = targetController;
            }
        }
Beispiel #6
0
 private void OnEnable()
 {
     targetInput = (IP_BaseAirplane_Input)target;
 }