Esempio n. 1
0
    // return the closest player patrol node
    protected int GetClosestPatrolNode(Vector3 target)
    {
        int closestPathNodeIndex = 0;

        for (int i = 0; i < patrolPath.PathNodes.Count; i++)
        {
            float distanceToPathNode = patrolPath.GetDistanceToNode(target, i);
            if (distanceToPathNode < patrolPath.GetDistanceToNode(target, closestPathNodeIndex))
            {
                closestPathNodeIndex = i;
            }
        }
        return(closestPathNodeIndex);
    }
Esempio n. 2
0
    // Return the closest node in patrol path and save the distance to it in distanceToNode
    protected int GetClosestPatrolNode(out float distanceToNode)
    {
        if (!patrolPath)
        {
            distanceToNode = fov.distanceTo(originPos);
            return(0);
        }
        int closestPathNodeIndex = 0;

        distanceToNode = 0;
        for (int i = 0; i < patrolPath.PathNodes.Count; i++)
        {
            float distanceToPathNode = patrolPath.GetDistanceToNode(transform.position, i);
            if (distanceToPathNode < patrolPath.GetDistanceToNode(transform.position, closestPathNodeIndex))
            {
                closestPathNodeIndex = i;
                distanceToNode       = distanceToPathNode;
            }
        }
        return(closestPathNodeIndex);
    }