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;
        }
Example #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;
        }
        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)
            {
                //Assing core Components
                controller.input           = input;
                controller.charactistics   = 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");

                graphicsGrp.transform.SetParent(rootGO.transform, false);
                collisionGrp.transform.SetParent(rootGO.transform, false);
                controlSurfaceGrp.transform.SetParent(rootGO.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/AirplanePhysics/Art/Objects/Airplanes/Indie-Pixel_Airplane/IndiePixel_Airplane.fbx", typeof(GameObject));
                if (defaultAirplane)
                {
                    GameObject.Instantiate(defaultAirplane, graphicsGrp.transform);
                }
            }

            //Select the Airplane Setup
            Selection.activeGameObject = rootGO;
        }
        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;
            }
        }
 void OnEnable()
 {
     targetInput = (IP_BaseAirplane_Input)target;
 }