void PointToGPSTarget()
 {
     if (weaponManager && weaponManager.designatedGPSCoords != Vector3d.zero)
     {
         StartCoroutine(PointToPositionRoutine(VectorUtils.GetWorldSurfacePostion(weaponManager.designatedGPSCoords, vessel.mainBody)));
     }
 }
        void FlyOrbit(FlightCtrlState s, Vector3d centerGPS, float radius, float speed, bool clockwise)
        {
            if (vessel.srfSpeed < minSpeed * 0.75f)
            {
                RegainEnergy(s);
                return;
            }

            debugString += "\nFlying orbit";
            Vector3 flightCenter = GetTerrainSurfacePosition(VectorUtils.GetWorldSurfacePostion(centerGPS, vessel.mainBody)) + (defaultAltitude * upDirection);

            Vector3 myVectorFromCenter = Vector3.ProjectOnPlane(vessel.transform.position - flightCenter, upDirection);
            Vector3 myVectorOnOrbit    = myVectorFromCenter.normalized * radius;

            Vector3 targetVectorFromCenter = Quaternion.AngleAxis(clockwise ? 15 : -15, upDirection) * myVectorOnOrbit;

            Vector3 verticalVelVector = Vector3.Project(vessel.srf_velocity, upDirection);             //for vv damping

            Vector3 targetPosition = flightCenter + targetVectorFromCenter - (verticalVelVector * 0.25f);

            Vector3 vectorToTarget = targetPosition - vesselTransform.position;
            Vector3 planarVel      = Vector3.ProjectOnPlane(vessel.srf_velocity, upDirection);

            vectorToTarget = Vector3.RotateTowards(planarVel, vectorToTarget, 25 * Mathf.Deg2Rad, 0);

            AdjustThrottle(speed, false);
            FlyToPosition(s, targetPosition);
        }
Beispiel #3
0
        protected void UpdateAntiRadiationTarget()
        {
            if (!TargetAcquired)
            {
                guidanceActive = false;
                return;
            }

            if (FlightGlobals.ready)
            {
                if (lockFailTimer < 0)
                {
                    lockFailTimer = 0;
                }
                lockFailTimer += Time.fixedDeltaTime;
            }

            if (lockFailTimer > 8)
            {
                guidanceActive = false;
                TargetAcquired = false;
            }
            else
            {
                TargetPosition = VectorUtils.GetWorldSurfacePostion(targetGPSCoords, vessel.mainBody);
            }
        }
        IEnumerator DelayedEnableRoutine()
        {
            if (delayedEnabling)
            {
                yield break;
            }
            delayedEnabling = true;

            Vector3d savedGTP = bodyRelativeGTP;

            Debug.Log("saved gtp: " + Misc.FormattedGeoPos(savedGTP, true));
            Debug.Log("groundStabilized: " + groundStabilized);

            while (TargetingCamera.Instance == null)
            {
                yield return(null);
            }
            while (!FlightGlobals.ready)
            {
                yield return(null);
            }
            while (FlightCamera.fetch == null)
            {
                yield return(null);
            }
            while (FlightCamera.fetch.mainCamera == null)
            {
                yield return(null);
            }
            while (vessel.packed)
            {
                yield return(null);
            }

            while (vessel.mainBody == null)
            {
                yield return(null);
            }

            EnableCamera();
            if (groundStabilized)
            {
                Debug.Log("Camera delayed enabled");
                groundTargetPosition = VectorUtils.GetWorldSurfacePostion(savedGTP, vessel.mainBody);                // vessel.mainBody.GetWorldSurfacePosition(bodyRelativeGTP.x, bodyRelativeGTP.y, bodyRelativeGTP.z);
                Vector3 lookVector = groundTargetPosition - cameraParentTransform.position;
                cameraParentTransform.rotation = Quaternion.LookRotation(lookVector, VectorUtils.GetUpDirection(cameraParentTransform.transform.position));
                GroundStabilize();
            }
            delayedEnabling = false;

            Debug.Log("post load saved gtp: " + bodyRelativeGTP);
        }
Beispiel #5
0
 protected void UpdateGPSTarget()
 {
     if (TargetAcquired)
     {
         TargetPosition     = VectorUtils.GetWorldSurfacePostion(targetGPSCoords, vessel.mainBody);
         TargetVelocity     = Vector3.zero;
         TargetAcceleration = Vector3.zero;
     }
     else
     {
         guidanceActive = false;
     }
 }
Beispiel #6
0
 protected void ReceiveRadarPing(Vessel v, Vector3 source, RadarWarningReceiver.RWRThreatTypes type, float persistTime)
 {
     if (TargetingMode == TargetingModes.AntiRad && TargetAcquired && v == vessel)
     {
         if ((source - VectorUtils.GetWorldSurfacePostion(targetGPSCoords, vessel.mainBody)).sqrMagnitude < Mathf.Pow(maxStaticLaunchRange / 4, 2) && //drastically increase update range for anti-radiation missile to track moving targets!
             Vector3.Angle(source - transform.position, GetForwardTransform()) < maxOffBoresight)
         {
             TargetAcquired     = true;
             TargetPosition     = source;
             targetGPSCoords    = VectorUtils.WorldPositionToGeoCoords(TargetPosition, vessel.mainBody);
             TargetVelocity     = Vector3.zero;
             TargetAcceleration = Vector3.zero;
             lockFailTimer      = 0;
         }
     }
 }
        void Update()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (cameraEnabled && TargetingCamera.ReadyForUse && vessel.IsControllable)
                {
                    if (delayedEnabling)
                    {
                        return;
                    }


                    if (!TargetingCamera.Instance || FlightGlobals.currentMainBody == null)
                    {
                        return;
                    }

                    if (activeCam == this)
                    {
                        if (zoomFovs != null)
                        {
                            TargetingCamera.Instance.SetFOV(fov);
                        }
                    }



                    if (radarLock)
                    {
                        UpdateRadarLock();
                    }

                    if (groundStabilized)
                    {
                        groundTargetPosition = VectorUtils.GetWorldSurfacePostion(bodyRelativeGTP, vessel.mainBody);                        //vessel.mainBody.GetWorldSurfacePosition(bodyRelativeGTP.x, bodyRelativeGTP.y, bodyRelativeGTP.z);
                        Vector3 lookVector = groundTargetPosition - cameraParentTransform.position;
                        cameraParentTransform.rotation = Quaternion.LookRotation(lookVector);
                    }



                    Vector3 lookDirection = cameraParentTransform.forward;
                    if (Vector3.Angle(lookDirection, cameraParentTransform.parent.forward) > gimbalLimit)
                    {
                        lookDirection      = Vector3.RotateTowards(cameraParentTransform.transform.parent.forward, lookDirection, gimbalLimit * Mathf.Deg2Rad, 0);
                        gimbalLimitReached = true;
                    }
                    else
                    {
                        gimbalLimitReached = false;
                    }

                    cameraParentTransform.rotation = Quaternion.LookRotation(lookDirection, VectorUtils.GetUpDirection(transform.position));

                    if (eyeHolderTransform)
                    {
                        Vector3 projectedForward = Vector3.ProjectOnPlane(cameraParentTransform.forward, eyeHolderTransform.parent.up);
                        if (projectedForward != Vector3.zero)
                        {
                            eyeHolderTransform.rotation = Quaternion.LookRotation(projectedForward, eyeHolderTransform.parent.up);
                        }
                    }

                    UpdateControls();
                    UpdateSlaveData();
                }
            }
        }