Пример #1
0
    private bool TestFleeDirection(BaseNavigator navigator, Vector3 dirFromThreat, float offsetDegrees, float minRange, float maxRange, out Vector3 result)
    {
        result = navigator.transform.position;
        Vector3 vector = Quaternion.Euler(0f, offsetDegrees, 0f) * dirFromThreat;
        Vector3 target = navigator.transform.position + vector * UnityEngine.Random.Range(minRange, maxRange);
        Vector3 position;

        if (!navigator.GetNearestNavmeshPosition(target, out position, 20f))
        {
            return(false);
        }
        if (!navigator.IsAcceptableWaterDepth(position))
        {
            return(false);
        }
        result = position;
        return(true);
    }
Пример #2
0
    public virtual Vector3 GetBestRoamPosition(BaseNavigator navigator, Vector3 fallbackPos, float minRange, float maxRange)
    {
        float radius = UnityEngine.Random.Range(minRange, maxRange);
        int   num    = 0;
        int   num2   = 0;
        float num3   = UnityEngine.Random.Range(0f, 90f);

        for (float num4 = 0f; num4 < 360f; num4 += 90f)
        {
            Vector3 pointOnCircle = GetPointOnCircle(navigator.transform.position, radius, num4 + num3);
            Vector3 position;
            if (navigator.GetNearestNavmeshPosition(pointOnCircle, out position, 10f) && navigator.IsAcceptableWaterDepth(position))
            {
                topologySamples[num] = position;
                num++;
                if (navigator.IsPositionATopologyPreference(position))
                {
                    preferedTopologySamples[num2] = position;
                    num2++;
                }
            }
        }
        if (UnityEngine.Random.Range(0f, 1f) <= 0.9f && num2 > 0)
        {
            chosenPosition = preferedTopologySamples[UnityEngine.Random.Range(0, num2)];
        }
        else if (num > 0)
        {
            chosenPosition = topologySamples[UnityEngine.Random.Range(0, num)];
        }
        else
        {
            chosenPosition = fallbackPos;
        }
        return(chosenPosition);
    }