示例#1
0
    // Simply clears waypoints and stops the vessel for predefined loiter time
    void Sentry()
    {
        // Simple control for exiting and entering Loiter
        if (!loiterOngoing)
        {
            loiterOngoing   = true;
            statusText.text = "loitering";
            loiterStart     = Time.timeSinceLevelLoad;
            ClearWaypoints();
        }
        if (Time.timeSinceLevelLoad - loiterTime > loiterStart)
        {
            flightStatus = FlightStatus.patrolling;

            // TODO request order instead
            wpList  = RouteAndManeuverPlanner.PlanPatrol(gameObject.transform.position);
            wpIndex = wpList.Count - 1;

            desiredSpeed    = patrolSpeedMax;
            generalThrust   = patrolThrust;
            loiterOngoing   = false;
            statusText.text = "";
            return;
        }

        Stop();
    }
示例#2
0
    //--------------------------------------
    #region Waypoint methods
    void WaypointCheck()
    {
        wpIndex = wpList.Count - 1;

        if (statusInFormation == StatusInFormation.lead)
        {
            if (wpList.Count == 0)
            {
                return;
            }                                  // sanity check

            // Check if the Vessel is close enough to the waypoint and if, then remove it
            Vector2 vectorToWP = wpList[wpIndex].wpCoordinates - gameObject.GetComponent <Rigidbody2D>().position;
            if (Vector2.SqrMagnitude(vectorToWP) < wpList[wpIndex].wpRadius * wpList[wpIndex].wpRadius)
            {
                wpList.RemoveAt(wpIndex);
                wpIndex = wpList.Count - 1;
            }

            if (wpList[wpIndex].temporary)
            {
                TempWPSanityCheck();
            }
        }

        headingToWaypoint = RouteAndManeuverPlanner.HeadingFromPositions(
            new Vector2(gameObject.transform.position.x, gameObject.transform.position.y),
            wpList[wpIndex].wpCoordinates
            );
    }
示例#3
0
    void InitialLockedManeuver()
    {
        Transform targetTransform = targetObject.transform;

        desiredHeading = RouteAndManeuverPlanner.GetInterceptHeading(targetTransform, gameObject.transform, initialSpeed);

        // ExecuteThrust(initialSpeed);
    }
示例#4
0
    void Pursue()
    {
        if (targetObject)
        {
            float distanceToTarget = Vector2.Distance(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y), new Vector2(targetObject.transform.position.x, targetObject.transform.position.y));

            // Switch to Roaming mode if target is out of radar range
            if (distanceToTarget > missile.radar.pingReach)
            {
                missileState = MissileState.roaming;
                CancelInvoke("Pursue");
                invokeSet = false;
                return;
            }

            Vector2 killBurn = RouteAndManeuverPlanner.GetHitBurn(targetObject.transform, gameObject.transform, missile.fuel, mass);
            desiredHeading = killBurn.x;
            if (Mathf.Abs(desiredHeading - missile.transform.eulerAngles.z) < 0.5f)
            {
                // ExecuteThrust(killBurn.y);
            }
        }
    }