예제 #1
0
        // Devuelve cierto (éxito, creo) si hay algún objeto a la distancia adecuada del objeto actual, en otro caso devuelve fallo
        public override TaskStatus OnUpdate()
        {
            Vector3 direction;

            // Comprueba cada objetivo. Todo lo que hace falta es un objetivo para ser capaces de devolver éxito
            for (int i = 0; i < targets.Length; ++i)
            {
                direction = targets[i].position - transform.position;
                // Comprueba para ver si la magnitud al cuadrado es menor que la especificada
                if (Vector3.SqrMagnitude(direction) < sqrMagnitude)
                {
                    // La magnitud es menr. Si hay línea de visión (lineOfSight) hacer una comprobación más
                    if (lineOfSight)
                    {
                        if (NPCViewUtilities.LineOfSight(transform, targets[i], direction))
                        {
                            // El objetivo tiene una magnitud menor que la magnitud especificada y está a la vista. Establece el objetivo y devuelve éxito
                            target.Value = targets[i];
                            return(TaskStatus.Success);
                        }
                    }
                    else
                    {
                        // El objetivo tiene una magnitud menor que la magnitud especificada. Establece el objetivo y devuelve éxito
                        target.Value = targets[i];
                        return(TaskStatus.Success);
                    }
                }
            }
            // No hay objetivos a la distancia apropiada. Devuelve fallo
            return(TaskStatus.Failure);
        }
예제 #2
0
        // returns success if any object is within distance of the current object. Otherwise it will return failure
        public override TaskStatus OnUpdate()
        {
            Vector3 direction;

            // check each target. All it takes is one target to be able to return success
            for (int i = 0; i < targets.Length; ++i)
            {
                direction = targets[i].position - transform.position;
                // check to see if the square magnitude is less than what is specified
                if (Vector3.SqrMagnitude(direction) < sqrMagnitude)
                {
                    // the magnitude is less. If lineOfSight is true do one more check
                    if (lineOfSight)
                    {
                        if (NPCViewUtilities.LineOfSight(transform, targets[i], direction))
                        {
                            // the target has a magnitude less than the specified magnitude and is within sight. Set the target and return success
                            target.Value = targets[i];
                            return(TaskStatus.Success);
                        }
                    }
                    else
                    {
                        // the target has a magnitude less than the specified magnitude. Set the target and return success
                        target.Value = targets[i];
                        return(TaskStatus.Success);
                    }
                }
            }
            // no targets are within distance. Return failure
            return(TaskStatus.Failure);
        }
예제 #3
0
        public override TaskStatus OnUpdate()
        {
            // succceed if a target is within sight
            for (int i = 0; i < targets.Length; ++i)
            {
                if (NPCViewUtilities.WithinSight(transform, targets[i], fieldOfViewAngle, sqrViewMagnitude))
                {
                    // set the target so the next task will know which transform it should target
                    target.Value = targets[i];
                    return(TaskStatus.Success);
                }
            }

            // we can only arrive at the next waypoint if the path isn't pending
            if (!navMeshAgent.pathPending)
            {
                var thisPosition = transform.position;
                thisPosition.y = navMeshAgent.destination.y; // ignore y
                if (Vector3.SqrMagnitude(thisPosition - navMeshAgent.destination) < SampleConstants.ArriveMagnitude)
                {
                    // cycle through the waypoints
                    waypointIndex            = (waypointIndex + 1) % waypoints.Length;
                    navMeshAgent.destination = waypoints[waypointIndex].position;
                }
            }

            // if no target is within sight then keep patroling
            return(TaskStatus.Running);
        }
예제 #4
0
        public override TaskStatus OnUpdate()
        {
            // Éxito si el objetivo está a la vista
            for (int i = 0; i < targets.Length; ++i)
            {
                if (NPCViewUtilities.WithinSight(transform, targets[i], fieldOfViewAngle, sqrViewMagnitude))
                {
                    // Establece el objetivo de modo que la siguiente tarea sepa que transformada debe poner como objetivo
                    target.Value = targets[i];
                    return(TaskStatus.Success);
                }
            }

            // Sólo podemos llevar al siguiente punto de ruta si la ruta no está pendiente
            if (!navMeshAgent.pathPending)
            {
                var thisPosition = transform.position;
                thisPosition.y = navMeshAgent.destination.y; // Ignora 'y'
                if (Vector3.SqrMagnitude(thisPosition - navMeshAgent.destination) < SampleConstants.ArriveMagnitude)
                {
                    // Cicla a través de todos los puntos de ruta
                    waypointIndex            = (waypointIndex + 1) % waypoints.Length;
                    navMeshAgent.destination = waypoints[waypointIndex].position;
                }
            }

            // Si no hay objetivo a la vista entonces sigue patrullando
            return(TaskStatus.Running);
        }
예제 #5
0
 public override TaskStatus OnUpdate()
 {
     // Return success if a target is within sight
     for (int i = 0; i < targets.Length; ++i)
     {
         if (NPCViewUtilities.WithinSight(transform, targets[i], fieldOfViewAngle, sqrViewMagnitude))
         {
             // set the target so other tasks will know which transform is within sight
             target.Value = targets[i];
             return(TaskStatus.Success);
         }
     }
     // a target is not within sight so return failure
     return(TaskStatus.Failure);
 }
예제 #6
0
 public override TaskStatus OnUpdate()
 {
     // Devuelve éxito si un objetivo está al alcance de la vista
     for (int i = 0; i < targets.Length; ++i)
     {
         if (NPCViewUtilities.WithinSight(transform, targets[i], fieldOfViewAngle, sqrViewMagnitude))
         {
             // Establece el objetivo de manera que otras tareas sepan la transformada que está a la vista
             target.Value = targets[i];
             return(TaskStatus.Success);
         }
     }
     // Un objetivo no está a la vista de modo que se devuelve fracaso
     return(TaskStatus.Failure);
 }
예제 #7
0
 // Draw the line of sight representation within the scene window
 public override void OnSceneGUI()
 {
     NPCViewUtilities.DrawLineOfSight(Owner.transform, fieldOfViewAngle, viewMagnitude);
 }
예제 #8
0
 // Draw the line of sight representation within the scene window
 public override void OnDrawGizmos()
 {
     NPCViewUtilities.DrawLineOfSight(Owner.transform, fieldOfViewAngle, sqrViewMagnitude);
 }