Beispiel #1
0
    SpwanPointEnemy GetAvailableSpawnPoint(SpwanPointEnemy[] spawnPoints)
    {
        Vector3 pos = Player.Instance.Agent.Position;

        float bestValue = 0;
        int   bestSpawn = -1;

        for (int i = 0; i < spawnPoints.Length; i++)
        {
            if (MyGameZone.IsEnemyInRange(spawnPoints[i].transform.position, 2))
            {
                continue;
            }
            float value = 0;
            float dist  = Mathf.Min(14, (spawnPoints[i].Transform.position - pos).magnitude);
            value = Mathfx.Hermite(0, 7, dist / 7);

            if (value <= bestValue)
            {
                continue;
            }

            bestValue = value;
            bestSpawn = i;
        }

        if (bestSpawn == -1)
        {
            return(spawnPoints[Random.Range(0, spawnPoints.Length)]);
        }
        return(spawnPoints[bestSpawn]);
    }
Beispiel #2
0
    SpawnPointEnemy GetAvailableSpawnPoint(SpawnPointEnemy[] spawnPoints)
    {
        Vector3 pos = Player.Instance.Agent.Position;

        float bestValue = 0;
        int   bestSpawn = -1;

        for (int i = 0; i < spawnPoints.Length; i++)
        {
            if (MyGameZone.IsEnemyInRange(spawnPoints[i].transform.position, 2))
            {
                //    Debug.Log(i + " Spawnpoint " + spawnPoints[i].name + " is near to enemy");
                continue;
            }

            float value = 0;
            float dist  = Mathf.Min(14, (spawnPoints[i].Transform.position - pos).magnitude);
            value = Mathfx.Hermite(0, 7, dist / 7);

            // Debug.Log(i + " Spawnpoint " + spawnPoints[i].name + " dist " + dist + " Value " + value);
            if (value <= bestValue)
            {
                continue;
            }

            bestValue = value;
            bestSpawn = i;
        }

        //Debug.Log("Best spaqwn point is " + bestSpawn);

        if (bestSpawn == -1)
        {
            return(spawnPoints[Random.Range(0, spawnPoints.Length)]);
        }

        return(spawnPoints[bestSpawn]);
    }