Пример #1
0
        private Vector3 FindRepositioningTargetAndGo()
        {
            NavMeshAgent navAgent = ai.navAgent;
            Vector2      moveTo;

            float radius = wanderingAreaRadius;

            for (int i = 0; i < 3; i++)
            {
                NavMeshPath path;
                moveTo = searchPoint + Random.insideUnitCircle * radius;
                if (navAgent.CanReach(moveTo, out path))
                {
                    navAgent.SetPath2D(path);
                    return(moveTo);
                }
                radius *= 0.5f;
            }

            moveTo = searchPoint + Random.insideUnitCircle * wanderingAreaRadius;
            NavMeshHit hit;

            if (navAgent.Raycast2D(moveTo, out hit))
            {
                moveTo = hit.position;
            }
            if (!navAgent.pathPending)
            {
                navAgent.SetDestination2D(moveTo);
            }
            return(moveTo);
        }