コード例 #1
0
    //TRIES TO ESTAY AWAY FROM ENEMIES. Calculate the vector for the avoidance of the enemies by computing the averange of the avoidance vector from the enemies
    Vector3 Avoidance()
    {
        Vector3 avoidVector = new Vector3();
        //get enemies within the range
        var enemyList = flockManager.GetEnemies(this, conf.avoidanceRadius);

        if (enemyList.Count == 0)
        {
            return(avoidVector);
        }
        //Calculate the average of the avoidance direction (go in the oposite direction of where the enemies are) and returns it
        foreach (var enemy in enemyList)
        {
            avoidVector += RunAway(enemy.position);
        }
        return(avoidVector.normalized);
    }