Esempio n. 1
0
        public override void OnUpdate()
        {
            base.OnUpdate();
            if (!HighLogic.LoadedSceneIsFlight)
                return;

            if (!invertSet) //run only the first time the craft is loaded
            {
                // test whether the engine is on the left or right side of the craft, for inverting the engine rotation and thrust based roll.
                if (Vector3.Dot(partTransform.position.normalized, vessel.ReferenceTransform.right) < 0) // below 0 means the engine is on the left side of the craft
                {
                    invertRotation = true;
                    //Debug.Log("Inverting left side VTOL rotation");
                }
                else
                {
                    invertRotation = false;
                }

                if (startInverted)
                    invertRotation = !invertRotation;
            }
            invertSet = true;

            if (!isInFrontOfCoMSet)
            {
                // test whether the engine is in the front or rear of the craft, for using double engine pair thrust based pitch.
                Transform CoMTransform = new GameObject().transform;
                CoMTransform.position = vessel.CoM;
                CoMTransform.rotation = vessel.transform.rotation;
                Vector3 relativePosition = CoMTransform.InverseTransformPoint(part.transform.position);
                if (relativePosition.y < 0)
                {
                    //Debug.Log("FSVTOLrotator: Engine is behind CoM: " + relativePosition);
                    isInFrontOfCoM = false;
                }
                else
                {
                    //Debug.Log("FSVTOLrotator: Engine is in front of CoM: " + relativePosition);
                    isInFrontOfCoM = true;
                }
            }
            isInFrontOfCoMSet = true;
            updateButtonTexts();

            #region VTOL steering

            FlightCtrlState ctrl = vessel.ctrlState;

            steerAngle = 0f;
            atmosphericNerf.steeringModifier = 1f;

            if (VTOLsteeringActive)
            {

                if (steerPitch)
                {
                    if (steerThrottlePitch)
                    {
                        float steerModifier = ctrl.pitch * SteeringMaxPitchThrottle;
                        if (isInFrontOfCoM)
                            steerModifier *= -1;
                        atmosphericNerf.steeringModifier -= steerModifier * steerDirection;
                    }
                    else
                    {
                        steerAngle -= ctrl.pitch * SteeringMaxPitch * steerDirection;
                        if (invertRotation)
                            steerAngle *= -1;
                    }
                }
                if (steerYaw)
                {
                    steerAngle -= ctrl.yaw * SteeringMaxYaw * steerDirection;
                }
                if (steerRoll)
                {
                    float steerModifier = ctrl.roll * SteeringMaxRoll;
                    if (invertRotation)
                        steerModifier *= -1;
                    atmosphericNerf.steeringModifier -= steerModifier * steerDirection;
                }
            }

            #endregion
        }
Esempio n. 2
0
 public void CreateStructure(bool isRepair = false, bool addColliders = true)
 {
     if (this._wasBuilt && isRepair)
     {
         if (this._bridgeRoot)
         {
             UnityEngine.Object.Destroy(this._bridgeRoot.gameObject);
         }
         this._bridgeRoot = null;
         base.StartCoroutine(this.DelayedAwake(true));
     }
     GameObject gameObject = (!this._bridgeRoot) ? null : this._bridgeRoot.gameObject;
     this._bridgeRoot = this.CreateBridge(this._anchor1.transform.position, this._anchor2.transform.position);
     this._bridgeRoot.name = "BridgeRoot" + ((!addColliders) ? "Ghost" : "Built");
     this._bridgeRoot.parent = base.transform;
     if (gameObject)
     {
         UnityEngine.Object.Destroy(gameObject);
     }
     if (addColliders)
     {
         base.transform.position = this._anchor1.transform.position;
         this._bridgeRoot.parent = base.transform;
         Vector3 vector = this._bridgeRoot.GetChild(0).position;
         int num = Mathf.CeilToInt(Vector3.Distance(this._anchor1.transform.position, this._anchor2.transform.position) / this._maxColliderLength);
         int num2 = Mathf.CeilToInt((float)this._bridgeRoot.childCount / (float)num);
         for (int i = 1; i <= num; i++)
         {
             int num3 = num2 * i;
             if (num3 >= this._bridgeRoot.childCount)
             {
                 num3 = this._bridgeRoot.childCount - 1;
             }
             Transform child = this._bridgeRoot.GetChild(num3);
             Vector3 position = child.position;
             Transform transform = new GameObject("Floor" + i).transform;
             transform.parent = base.transform;
             transform.position = vector;
             transform.LookAt(position);
             BoxCollider boxCollider = transform.gameObject.AddComponent<BoxCollider>();
             boxCollider.center = transform.InverseTransformPoint(Vector3.Lerp(vector, position, 0.5f));
             boxCollider.size = new Vector3(4.5f, this._logWidth, Vector3.Distance(vector, position));
             transform.tag = "UnderfootWood";
             vector = position;
         }
     }
     if (this._wasBuilt && isRepair)
     {
         this._bridgeRoot.parent = base.transform;
     }
 }