Exemplo n.º 1
0
 void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == tagPrey)
     {
         //agent.SetDestination(new Vector3(0,0,0));
         // Destroy(collision.gameObject);
         MovePoule controlCollisionPrey = collision.gameObject.GetComponent <MovePoule>();
         if (controlCollisionPrey.touched == false)
         {
             controlCollisionPrey.touched            = true; // access this particular touched variable
             collision.gameObject.transform.position = homePoule;
         }
         else
         {
             // print(gameObject.name + " : Get out of my way !!") ;
         }
     }
     else if (collision.gameObject.tag == tagFriend)
     {
         MoveRenard controlCollisiontFriend = collision.gameObject.GetComponent <MoveRenard>();
         if (controlCollisiontFriend.touched == true && touched == false)
         {
             controlCollisiontFriend.touched = false;
         }
         else
         {
             // print("Pardon copain");
         }
     }
 }
Exemplo n.º 2
0
 bool amiArreteEnVue(out Vector3 cible)
 {
     if (friendListMinusMe.Count != 0)
     { // test seulement dans le cas ou le renard est seule (test unitaire)
         List <GameObject> friendArrestedVisibleList = new List <GameObject>();
         cible = Vector3.zero;
         unCamaradeALiberer = false;
         foreach (GameObject camarade in friendListMinusMe)
         {
             MoveRenard controlFriendArrested = camarade.GetComponent <MoveRenard>();
             bool       friendArrested        = controlFriendArrested.touched; // access this particular touched variable
             // on teste si la prey est a distance de vue  ..................................  et    dans le champ de vision  ...........................................................................    et    s'il n'y a pas une proie plus proche
             if (((camarade.transform.position - agent.transform.position).magnitude < sightRange) && (Vector3.Angle(camarade.transform.position - agent.transform.position, agent.transform.forward) < sightAngle) && (friendArrested == true))
             {
                 unCamaradeALiberer = true;
                 friendArrestedVisibleList.Add(camarade);
             }
         }
         Transform tempResult = getClosest(friendArrestedVisibleList);
         cible = tempResult.position;
         return(unCamaradeALiberer);
     }
     else
     {
         cible = new Vector3(0.0f, 0.0f, 0.0f);
         unCamaradeALiberer = false;
         return(unCamaradeALiberer);
     }
 }
    bool CibleEnVue(out Vector3 result)
    {
      if(preyList.Length != 0){  // test seulement dans le cas ou la poule est seule (test unitaire)

        List<GameObject> preyVisibleList = new List<GameObject>();
        result = Vector3.zero;
        enChasse = false ;
        for (int i = 0; i < preyList.Length; i++)
        {
              GameObject prey = preyList[i];
              MoveRenard controlPreyTouched = prey.GetComponent<MoveRenard>();
              preyTouched = controlPreyTouched.touched; // access this particular touched variable
              // on teste si la prey est a distance de vue  ..................................  et    dans le champ de vision  ...........................................................................    et    s'il n'y a pas une proie plus proche
              if ( ((prey.transform.position - agent.transform.position).magnitude < sightRange) && (Vector3.Angle(prey.transform.position - agent.transform.position, agent.transform.forward) < sightAngle) && (preyTouched == false) )
                {
                  enChasse = true ;
                  preyVisibleList.Add(prey) ;

                }
          }
          Transform tempResult = getClosest(preyVisibleList);
          result = tempResult.position ;
          return enChasse;
      }
      else
      { result = new Vector3 (0.0f,0.0f,0.0f);
        enChasse=false;
        return enChasse;}
    }
 bool endOfGame()
 {
   for (int j = 0; j < preyList.Length; j++)
     {
       prey = preyList[j] ;
       MoveRenard controlTouchedPrey = prey.GetComponent<MoveRenard>();
       preyTouched = controlTouchedPrey.touched;
       if(preyTouched == false)
       {
         return false;
       }
     }
     return true;
 }
 bool prisPourCible(out Vector3 result)
 {
     for (int i = 0; i < predatorList.Length; i++)
     {
         GameObject predator = predatorList[i];
         MoveRenard controlPredatorTouched = predator.GetComponent <MoveRenard>();
         predatorTouched = controlPredatorTouched.touched; // access this particular touched variable
         if (((predator.transform.position - agent.transform.position).magnitude < sightRange) && (predatorTouched == false))
         {
             Vector3 cibleDir = predator.transform.position - agent.transform.position;
             if (Vector3.Angle(cibleDir, agent.transform.forward) < sightAngle)
             {
                 result       = predator.transform.position;
                 prisEnChasse = true;
                 return(true);
             }
         }
     }
     result = Vector3.zero;
     return(false);
 }
Exemplo n.º 6
0
    bool getPlusProcheAmiArrete(out Vector3 result)
    {
        List <GameObject> friendArreteList = new List <GameObject>();

        amiArrete = false;
        foreach (GameObject friend in friendListMinusMe)
        {
            MoveRenard controlTouchedFriend = friend.GetComponent <MoveRenard>();
            bool       friendTouched        = controlTouchedFriend.touched; // access this particular touched variable
            // on teste si la prey est a distance de vue  ..................................  et    dans le champ de vision  ...........................................................................    et    s'il n'y a pas une proie plus proche
            if (friendTouched == true)
            {
                friendArreteList.Add(friend);
                amiArrete = true;
            }
        }
        Transform tempResult = getClosest(friendArreteList);

        result = tempResult.position;
        return(amiArrete);
    }