Пример #1
0
        bool DetectCollision(Vector3 direction)
        {
            if (MissileGuidance.GetRadarAltitude(vessel) < 20)
            {
                return(false);
            }

            direction = direction.normalized;
            int        layerMask = 557057;
            Ray        ray       = new Ray(vesselTransform.position + (50 * vesselTransform.up), direction);
            float      distance  = Mathf.Clamp((float)vessel.srfSpeed * 5, 250, 2500);
            RaycastHit hit;

            if (Physics.SphereCast(ray, 10, out hit, distance, layerMask))
            {
                Rigidbody otherRb = hit.collider.attachedRigidbody;
                if (otherRb)
                {
                    if (Vector3.Dot(otherRb.velocity, vessel.srf_velocity) < 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        void TakeOff(FlightCtrlState s)
        {
            threatLevel  = 1;
            debugString += "\nTaking off/Gaining altitude";

            if (vessel.Landed && vessel.srfSpeed < takeOffSpeed)
            {
                return;
            }

            steerMode = SteerModes.Aiming;

            float radarAlt = MissileGuidance.GetRadarAltitude(vessel);

            Vector3 forwardPoint = vessel.transform.position + Vector3.ProjectOnPlane(vesselTransform.up * 100, upDirection);
            float   terrainDiff  = MissileGuidance.GetRaycastRadarAltitude(forwardPoint) - radarAlt;

            terrainDiff = Mathf.Max(terrainDiff, 0);

            float rise = Mathf.Clamp((float)vessel.srfSpeed * 0.3f, 5, 100);

            if (radarAlt > 70)
            {
                vessel.ActionGroups.SetGroup(KSPActionGroup.Gear, false);
            }
            else
            {
                vessel.ActionGroups.SetGroup(KSPActionGroup.Gear, true);
            }

            FlyToPosition(s, forwardPoint + (upDirection * (rise + terrainDiff)));

            if (radarAlt > minAltitude)
            {
                startedLanded = false;
            }
        }
Пример #3
0
        void AutoPilot(FlightCtrlState s)
        {
            if (!vessel || !vessel.transform || vessel.packed || !vessel.mainBody)
            {
                return;
            }
            vesselTransform = vessel.ReferenceTransform;

            //default brakes off full throttle
            //s.mainThrottle = 1;

            //vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false);
            AdjustThrottle(maxSpeed, true);
            useAB     = true;
            useBrakes = true;
            vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true);

            steerMode = SteerModes.NormalFlight;


            GetGuardTarget();
            if (vessel.Landed && standbyMode && weaponManager && BDATargetManager.TargetDatabase[BDATargetManager.BoolToTeam(weaponManager.team)].Count == 0)
            {
                //s.mainThrottle = 0;
                //vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true);
                AdjustThrottle(0, true);
                return;
            }
            //upDirection = -FlightGlobals.getGeeForceAtPosition(transform.position).normalized;
            upDirection = VectorUtils.GetUpDirection(vessel.transform.position);
            debugString = string.Empty;
            if (MissileGuidance.GetRadarAltitude(vessel) < minAltitude)
            {
                startedLanded = true;
            }



            if (startedLanded)
            {
                TakeOff(s);
                turningTimer = 0;
            }
            else
            {
                if (FlyAvoidCollision(s))
                {
                    turningTimer = 0;
                }
                else if (command != PilotCommands.Free)
                {
                    UpdateCommand(s);
                }
                else
                {
                    UpdateAI(s);
                }
            }

            //brake and cut throttle if exceeding max speed

            /*
             * if(vessel.srfSpeed > maxSpeed)
             * {
             *      vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true);
             *      s.mainThrottle = 0;
             * }
             */

            debugString += "\nthreatLevel: " + threatLevel;
        }