Exemplo n.º 1
0
        private Vector3 CruiseGuidance()
        {
            Vector3 cruiseTarget = Vector3.zero;
            float   distance     = Vector3.Distance(TargetPosition, vessel.CoM);

            if (distance < 4500)
            {
                cruiseTarget = MissileGuidance.GetTerminalManeuveringTarget(TargetPosition, vessel, CruiseAltitude);
                debugString += "\nTerminal Maneuvers";
            }
            else
            {
                float agmThreshDist = 2500;
                if (distance < agmThreshDist)
                {
                    if (!MissileGuidance.GetBallisticGuidanceTarget(TargetPosition, vessel, true, out cruiseTarget))
                    {
                        cruiseTarget = MissileGuidance.GetAirToGroundTarget(TargetPosition, vessel, 1.85f);
                    }

                    debugString += "\nDescending On Target";
                }
                else
                {
                    cruiseTarget = MissileGuidance.GetCruiseTarget(TargetPosition, vessel, CruiseAltitude);
                    debugString += "\nCruising";
                }
            }

            debugString += "\nRadarAlt: " + MissileGuidance.GetRadarAltitude(vessel);

            return(cruiseTarget);
        }
Exemplo n.º 2
0
        public void GuidanceSteer(FlightCtrlState s)
        {
            if (guidanceActive && targetVessel != null && vessel != null && vesselTransform != null && velocityTransform != null)
            {
                velocityTransform.rotation = Quaternion.LookRotation(vessel.srf_velocity, -vesselTransform.forward);
                Vector3 targetPosition = targetVessel.CoM;
                Vector3 localAngVel    = vessel.angularVelocity;

                if (guidanceMode == 1)
                {
                    targetPosition = MissileGuidance.GetAirToAirTarget(targetPosition, vessel.srf_velocity, vessel.acceleration, vessel, out timeToImpact);
                }
                else if (guidanceMode == 2)
                {
                    targetPosition = MissileGuidance.GetAirToGroundTarget(targetPosition, vessel, 1.85f);
                }
                else
                {
                    targetPosition = MissileGuidance.GetCruiseTarget(targetPosition, vessel, cruiseAltitude);
                }

                Vector3 targetDirection = velocityTransform.InverseTransformPoint(targetPosition).normalized;
                targetDirection = Vector3.RotateTowards(Vector3.forward, targetDirection, 15 * Mathf.Deg2Rad, 0);



                float steerYaw   = (steerMult * targetDirection.x) - (steerDamping * -localAngVel.z);
                float steerPitch = (steerMult * targetDirection.y) - (steerDamping * -localAngVel.x);

                s.yaw   = Mathf.Clamp(steerYaw, -maxSteer, maxSteer);
                s.pitch = Mathf.Clamp(steerPitch, -maxSteer, maxSteer);

                s.mainThrottle = 1;
            }
        }