Ejemplo n.º 1
0
        /// <summary>
        /// Gets the laser target painter with the least angle off boresight. Set the missile as the reference transform.
        /// </summary>
        /// <returns>The laser target painter.</returns>
        /// <param name="referenceTransform">Reference transform.</param>
        /// <param name="maxBoreSight">Max bore sight.</param>
        public static ModuleTargetingCamera GetLaserTarget(MissileLauncher ml)
        {
            Transform referenceTransform = ml.transform;
            float maxOffBoresight = ml.maxOffBoresight;
            ModuleTargetingCamera finalCam = null;
            float smallestAngle = 360;
            foreach(var cam in ActiveLasers)
            {
                if(!cam)
                {
                    continue;
                }

                if(cam.cameraEnabled && cam.groundStabilized && cam.surfaceDetected && !cam.gimbalLimitReached)
                {
                    float angle = Vector3.Angle(referenceTransform.forward, cam.groundTargetPosition-referenceTransform.position);
                    if(angle < maxOffBoresight && angle < smallestAngle && ml.CanSeePosition(cam.groundTargetPosition))
                    {
                        smallestAngle = angle;
                        finalCam = cam;
                    }
                }
            }
            return finalCam;
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Gets the laser target painter with the least angle off boresight. Set the missile as the reference transform.
		/// </summary>
		/// <returns>The laser target painter.</returns>
		/// <param name="referenceTransform">Reference transform.</param>
		/// <param name="maxBoreSight">Max bore sight.</param>
		public static ModuleTargetingCamera GetLaserTarget(MissileLauncher ml, bool parentOnly)
		{
			Transform referenceTransform = ml.transform;
			float maxOffBoresight = ml.maxOffBoresight;
			ModuleTargetingCamera finalCam = null;
			float smallestAngle = 360;
			foreach(var cam in ActiveLasers)
			{
				if(!cam)
				{
					continue;
				}

				if(parentOnly && !(cam.vessel == ml.vessel || cam.vessel == ml.sourceVessel))
				{
					continue;
				}


				if(cam.cameraEnabled && cam.groundStabilized && cam.surfaceDetected && !cam.gimbalLimitReached)
				{
					/*
					if(ml.guidanceMode == MissileLauncher.GuidanceModes.BeamRiding && Vector3.Dot(ml.transform.position - cam.transform.position, ml.transform.forward) < 0)
					{
						continue;
					}
					*/

					float angle = Vector3.Angle(referenceTransform.forward, cam.groundTargetPosition-referenceTransform.position);
					if(angle < maxOffBoresight && angle < smallestAngle && ml.CanSeePosition(cam.groundTargetPosition))
					{
						smallestAngle = angle;
						finalCam = cam;
					}
				}
			}
			return finalCam;
		}