Beispiel #1
0
 /*
  * Checks the aggroRange for enemies and chose the next one. Only works if there isn't
  * an opponent declared as @opponent.
  */
 private void checkRadiusForOpponents()
 {
     if (!hasOpponent() || opponent.GetComponent <Creature>().isDead)
     {
         float npcDistance = 99999999;
         foreach (string enemy in enemies)
         {
             GameObject[] npcs = GameObject.FindGameObjectsWithTag(enemy);
             foreach (GameObject npc in npcs)
             {
                 float distance = Vector3.Distance(npc.transform.position, transform.position);
                 if (distance != 0 && distance < aggroRange)
                 {
                     if (opponent == null || distance < npcDistance)
                     {
                         opponent      = npc;
                         npcDistance   = distance;
                         lastChaseTime = Time.time;
                     }
                 }
             }
         }
     }
     else if (Vector3.Distance(opponent.transform.position, transform.position) > aggroRange && !npcInChasingTime())
     {
         //aggroMeter.deleteAggro (opponent);
         aggroMeter = new AggroMeter();
         opponent   = null;
     }
 }
Beispiel #2
0
 /* ------------------------------ Live and walk ------------------------------ */
 protected void live()
 {
     opponent   = null;
     aggroMeter = new AggroMeter();
     resetAttackCooldowns();
     if (walking)
     {
         goToPosition(currentGoal);
     }
     else if (Vector3.Distance(startPosition, transform.position) > livingRadius)
     {
         randomNextWalkIn();
         currentGoal = startPosition;
         goToPosition(currentGoal);
     }
     else
     {
         if (nextWalk + lastWalkTime < Time.time)
         {
             randomNextWalkIn();
             currentGoal   = randomPlaceInLivingRadius();
             currentGoal.y = startPosition.y;                 // else the circle-bug will happen
             goToPosition(currentGoal);
         }
     }
 }