Пример #1
0
 /****************************************************************
 * Name - Subroutine GETTAR
 * Purpose - Provides a moving target.
 * Variables -
 * NAME TYPE UNITS
 *------------------------------------------------------------
 * TARX REAL earth-based X
 * TARY REAL earth-based Y
 * TARZ REAL earth-based Z
 * ITMIN INTEGER (# of iterations per second)
 ****************************************************************/
 private void Gettar(ref float tarx, ref float tary, ref float tarz, GameObject targetObject)
 {
     //  float mach = 234.375f;
     tarx = MathCalculations.ConvertUnityToMeters(targetObject.transform.localPosition.x, false);
     tary = MathCalculations.ConvertUnityToMeters(targetObject.transform.localPosition.y, true);
     tarz = MathCalculations.ConvertUnityToMeters(targetObject.transform.localPosition.z, true);
 }
Пример #2
0
    public bool CalculateIsTargetHit(GameObject ownShip, GameObject targetAircraft, MissileData missileData, ref float probability)
    {
        probability = GetHitProbability(ownShip.transform.GetChild(0).gameObject, targetAircraft.transform.GetChild(0).gameObject, missileData.Range);
        ExtractConstantsFromMissileData(missileData);
        Vector3 ownerPosition  = ownShip.transform.localPosition;
        Vector3 ownerDirection = ownShip.transform.localRotation.eulerAngles;
        //Velocity, Pitch Rate, Yaw Rate, Pitch and Yaw
        float velcty, pitchr, yawr, pitch, yaw;
        //Position of missile, weight of missile, range (distance of missile and target)
        //Get this value from data table
        float x, y, z, range;

        range = -1;
        int loop1, loop2;
        //Target's x y z
        float tarx, tary, tarz;

        //Iterations per second
        int itmin;

        itmin = 128;


        //Pitch signal, Yaw signal
        float pthsig, yawsig;


        int hit, miss;
        //Last iteration position
        float otarx, otary, otarz;

        velcty = 200.0f;
        pitchr = 0.0f;
        yawr   = 0.0f;
        pthsig = 0.0f;
        yawsig = 0.0f;
        pitch  = ownerDirection.x * Mathf.Deg2Rad;
        yaw    = ownerDirection.y * Mathf.Deg2Rad;


        x = MathCalculations.ConvertUnityToMeters(ownerPosition.x, false);
        y = MathCalculations.ConvertUnityToMeters(ownerPosition.y, true);
        z = MathCalculations.ConvertUnityToMeters(ownerPosition.z, true);


        tarx = 0;
        tary = 0;
        tarz = 0;
        Gettar(ref tarx, ref tary, ref tarz, targetAircraft);

        hit  = 0;
        miss = 0;

        //Lets assume this loop1 = seconds
        for (loop1 = 1; loop1 <= 30; loop1++)
        {
            //For each second do 128 times
            for (loop2 = 1; loop2 <= itmin; loop2++)
            {
                otarx = tarx;
                otary = tary;
                otarz = tarz;
                Gettar(ref tarx, ref tary, ref tarz, targetAircraft);
                Calculations(ref velcty, ref pitchr, ref pthsig, ref yawr, ref yawsig
                             , ref pitch, ref yaw, ref x, ref y, ref z, ref tarx, ref tary, ref tarz, ref loop1,
                             ref loop2, ref itmin, ref hit, ref miss, ref otarx, ref otary, ref otarz, ref range);
                if (hit == 1)
                {
                    Debug.Log(string.Format("Target X = {0}, Target Y = {1}, Target Z = {2}", tarx, tary, tarz));
                    return(true);
                }
                if (miss == 1)
                {
                    return(false);
                }
                //Continue if still indeterminate
            }
        }

        return(hit == 1);
    }