Ejemplo n.º 1
0
    public PlayerMissile Create(Transform pool, EnemySwarm enemySwarm)
    {
        PlayerMissile missile = Create <PlayerMissile>(pool);

        missile._enemySwarm = enemySwarm;
        return(missile);
    }
Ejemplo n.º 2
0
    public void SpawnEnemyBatch(int EnemyNumber, EnemySwarm EnemyPrefab, Vector3 AreaCenter, float AreaRadius)
    {
        for (int i = 0; i < EnemyNumber; i++)
        {
            if (SpawnedEnemiesCounter >= SpawnedEnemiesMaxNumber)
            {
                return;
            }

            // Decide the next enemy spawn position and check if it was possible to generate such a position:
            if (!GenerateSpawnPosition(AreaCenter, AreaRadius))
            {
                return;
            }

            if (!CalculateNextSpawnNumber())
            {
                return;
            }

            SpawnedEnemies[SpawnedEnemiesIDCounter] = Instantiate(EnemyPrefab, spawnPos, EnemyPrefab.transform.rotation);
            SpawnedEnemies[SpawnedEnemiesIDCounter].InitializeSwarmling(this, SpawnedEnemiesIDCounter, Players, LayerMask, SwarmlingHealthFactor, BossBeetlesHealOnDeathFactor);

            // At this point an enemy was succesfully spawned:
            SpawnedEnemiesCounter++;
        }
    }
Ejemplo n.º 3
0
    public void SwarmlingBaseRulesCalculation()
    {
        // NeighbourColliders = Physics.OverlapSphere(SwarmlingTransform.position, NeighbourRadius, NeighbourLayerMask);
        // Stop if not enough Neighbours:
        if (NeighbourCount < 2)
        {
            return;
        }

        CohesionVec   = Vector3.zero;
        SeperationVec = Vector3.zero;
        AlignmentVec  = Vector3.zero;

        CohesionNumber   = 0;
        SeperationNumber = 0;
        AlignmentNumber  = 0;

        DistanceVec    = Vector3.zero;
        DistanceVecMag = 0;

        ConfidenceCurrent = 0;

        for (int i = 0; i < NeighbourCount; i++)
        {
            if (!NeighbourColliders[i])
            {
                continue;
            }

            CurrentSwarmling = NeighbourColliders[i].GetComponent <EnemySwarm>();

            if (CurrentSwarmling.IgnoreThisSwarmlingForOthers)
            {
                if (DistanceVecMag <= Mathf.Pow(AlignmentDistance, 2)) // Could be optimized by storing the pow2 distance!
                {
                    ConfidenceCurrent++;
                }

                continue;
            }

            DistanceVec    = SwarmlingTransform.position - CurrentSwarmling.SwarmlingTransform.position;
            DistanceVecMag = DistanceVec.sqrMagnitude;

            if (DistanceVecMag <= 0)
            {
                continue;
            }

            // Cohesion:
            if (DistanceVecMag <= Mathf.Pow(CohesionDistance, 2)) // Could be optimized by storing the pow2 distance!
            {
                CohesionVec += CurrentSwarmling.SwarmlingTransform.position;
                CohesionNumber++;
            }

            // Seperation:
            if (DistanceVecMag <= Mathf.Pow(SeperationDistance, 2)) // Could be optimized by storing the pow2 distance!
            {
                SeperationVec += DistanceVec / DistanceVecMag;
                SeperationNumber++;
            }

            // Alignment:
            if (DistanceVecMag <= Mathf.Pow(AlignmentDistance, 2)) // Could be optimized by storing the pow2 distance!
            {
                AlignmentVec += CurrentSwarmling.Velocity;
                AlignmentNumber++;
                ConfidenceCurrent++;
            }
        }
        // Cohesion:
        if (CohesionNumber > 0)
        {
            //CohesionVec = Vector3.ClampMagnitude(((CohesionVec / CohesionNumber) - SwarmlingTransform.position), DesiredBaseSpeed);
            //Debug.Log("Cohesion: " + CohesionVec);
            CohesionVec = CohesionVec / CohesionNumber;
            CohesionVec = CohesionVec - SwarmlingTransform.position;
            CohesionVec = CohesionVec.normalized * DesiredBaseSpeed;

            CohesionVec = Steer(CohesionVec);

            Acceleration += CohesionVec * CohesionFactor;
            GoalFactor   += CohesionFactor;
        }

        // Seperation:
        if (SeperationNumber > 0)
        {
            if (NoSeperationThisUpdate)
            {
                NoSeperationThisUpdate = false;
            }
            else
            {
                //SeperationVec = Vector3.ClampMagnitude((SeperationVec / SeperationNumber), DesiredBaseSpeed);
                //Debug.Log("SeperationVec: " + SeperationVec);
                SeperationVec = SeperationVec.normalized * DesiredBaseSpeed;

                SeperationVec = Steer(SeperationVec);
                Acceleration += SeperationVec * SeperationFactor;

                GoalFactor += SeperationFactor;
            }
        }

        // Alignment:
        if (AlignmentNumber > 0)
        {
            //AlignmentVec = Vector3.ClampMagnitude((AlignmentVec/AlignmentNumber), DesiredBaseSpeed);
            //Debug.Log("AlignmentVec: " + AlignmentVec);

            AlignmentVec = AlignmentVec.normalized * DesiredBaseSpeed;

            //AlignmentVec = AlignmentVec / AlignmentNumber;

            AlignmentVec = Steer(AlignmentVec);

            Acceleration += AlignmentVec * AlignmentFactor;
            GoalFactor   += AlignmentFactor;
        }

        ConfidenceCurrent = 1 - ConfidenceCurrent / (NeighbourColliders.Length - 1);
    }
Ejemplo n.º 4
0
 public void RemoveFromEnemiesInRange(EnemySwarm RemoveEnemySwarm)
 {
     EnemiesInRange.Remove(RemoveEnemySwarm);
 }
Ejemplo n.º 5
0
/*
 *  private void RuleDangerAvoidanceEnhanced()
 *  {
 *      // Dangers in Range:
 *      int NumberOfDangers = DangerInRange.Count;
 *
 *      Vector3 DangerVec = Vector3.zero;
 *      int DangerVecNumber = 0;
 *
 *      Vector3 DistanceVec = Vector3.zero;
 *      float DistanceVecMag = 0;
 *
 *      for (int i = 0; i < NumberOfDangers; i++)
 *      {
 *          DistanceVec = transform.position - DangerInRange[i].transform.position;
 *          DistanceVecMag = DistanceVec.sqrMagnitude;
 *
 *          if (DistanceVecMag <= DangerDistance * DangerDistance)
 *          {
 *              DangerVec += DistanceVec.normalized / Mathf.Sqrt(DistanceVecMag);
 *              DangerVecNumber++;
 *          }
 *      }
 *
 *      // Player Hit Objects In Range:
 *      List<SkillHitObject> PlayerHitObjects = CAttention.GetPlayerHitObjectsInAttentionRange();
 *      NumberOfDangers = PlayerHitObjects.Count;
 *
 *      for (int i = 0; i < NumberOfDangers; i++)
 *      {
 *          if (PlayerHitObjects[i])
 *          {
 *              DistanceVec = transform.position - PlayerHitObjects[i].transform.position;
 *              DistanceVecMag = DistanceVec.sqrMagnitude;
 *
 *              if (DistanceVecMag <= DangerDistance * DangerDistance)
 *              {
 *                  DangerVec += DistanceVec.normalized / Mathf.Sqrt(DistanceVecMag);
 *                  DangerVecNumber++;
 *              }
 *          }
 *      }
 *
 *      // Players in Range:
 *      NumberOfDangers = PlayersInRange.Count;
 *
 *      for (int i = 0; i < NumberOfDangers; i++)
 *      {
 *          DistanceVec = transform.position - PlayersInRange[i].transform.position;
 *          DistanceVecMag = DistanceVec.sqrMagnitude;
 *
 *          if (DistanceVecMag <= (DangerDistance * 0.6f) * (DangerDistance * 0.6f)
 *              && PlayersInRange[i].GetCurrentThreatLevel(true, false) >= 2
 *              && (Vector3.Dot(PlayersInRange[i].transform.forward, (PlayersInRange[i].transform.position - transform.position).normalized) < 0.3f))
 *          {
 *              DangerVec += DistanceVec.normalized / Mathf.Sqrt(DistanceVecMag);
 *              DangerVecNumber++;
 *          }
 *      }
 *
 *      if (DangerVecNumber >= 1)
 *      {
 *          DangerVec = DangerVec.normalized * GetDesiredRunSpeed();
 *
 *          DangerVec = Steer(DangerVec);
 *          Acceleration += DangerVec * EnemyTestSwarm.Instance.DangerFactor;
 *          GoalFactor += EnemyTestSwarm.Instance.DangerFactor;
 *      }
 *  }*/

    // ===========================================/ RULE: DANGER AVOIDANCE /============================================

    // =============================================== RULE: ATTRACTION ================================================
    // Enemies steer towards the nearest attraction (in this case Player Characters, so far).

/*
 *  private void RuleAttraction()
 *  {
 *      int NumberOfOthers = PlayersInRange.Count;
 *
 *      Vector3 AttractionVec = Vector3.zero;
 *      float AttractionVecMag = AttractionDistance * AttractionDistance + 1;
 *
 *      Vector3 DistanceVec = Vector3.zero;
 *      float DistanceVecMag = 0;
 *
 *      for (int i = 0; i < NumberOfOthers; i++)
 *      {
 *          DistanceVec = PlayersInRange[i].transform.position - transform.position;
 *          DistanceVecMag = DistanceVec.sqrMagnitude;
 *
 *          if (DistanceVecMag <= AttractionDistance * AttractionDistance
 *              && DistanceVecMag < AttractionVecMag)
 *          {
 *              AttractionVec = DistanceVec;
 *              AttractionVecMag = DistanceVecMag;
 *          }
 *      }
 *
 *      if (AttractionVecMag < AttractionDistance * AttractionDistance + 1)
 *      {
 *          AttractionVec = AttractionVec.normalized * GetDesiredSpeed();
 *
 *          AttractionVec = Steer(AttractionVec);
 *          Acceleration += AttractionVec * AttractionFactor;
 *          GoalFactor += AttractionFactor;
 *      }
 *  }
 */
    // ==============================================/ RULE: ATTRACTION /===============================================

    // ============================================== RULE: GO TO BORDER ===============================================
    // Tank Enemies should steer towards the outside of the swarm.

    /*
     * private void RuleGoToBorder()
     * {
     *  int NumberOfOthers = EnemiesInRange.Count;
     *
     *  Vector3 BorderVec = Vector3.zero;
     *  int BorderNumber = 0;
     *
     *  Vector3 DistanceVec = Vector3.zero;
     *  float DistanceVecMag = 0;
     *
     *  for (int i = 0; i < NumberOfOthers; i++)
     *  {
     *      DistanceVec = transform.position - EnemiesInRange[i].transform.position;
     *      DistanceVecMag = DistanceVec.sqrMagnitude;
     *
     *      if (DistanceVecMag <= BorderDistance * BorderDistance && EnemiesInRange[i].GetSwarmType() != SType)
     *      {
     *          BorderVec += EnemiesInRange[i].transform.position;
     *          BorderNumber++;
     *      }
     *  }
     *
     *  if (BorderNumber >= 2)
     *  {
     *      BorderVec = BorderVec / BorderNumber;
     *      BorderVec = this.transform.position - BorderVec;
     *
     *      float NewFactor = Mathf.Max(BorderDistance - BorderVec.magnitude, 0);
     *      BorderVec = BorderVec.normalized * GetDesiredRunSpeed() * NewFactor;
     *
     *      BorderVec = Steer(BorderVec);
     *      Acceleration += BorderVec * BorderFactor;
     *      GoalFactor += BorderFactor;
     *
     *      NoSeperationThisUpdate = true;
     *  }
     * }
     */
    // =============================================/ RULE: GO TO BORDER /==============================================

    // ====================================================/ RULES /====================================================


    // ================================================== NEARBY LISTS ==================================================

    public void AddToEnemiesInRange(EnemySwarm AddEnemySwarm)
    {
        EnemiesInRange.Add(AddEnemySwarm);
    }
Ejemplo n.º 6
0
 public void RemoveFromList(EnemySwarm SwarmObject)
 {
     Owner.RemoveFromEnemiesInRange(SwarmObject);
 }