Forum begins after the advertisement:
See discounted assets
:: For relativeSpawnpoints, I have 8 points around the player. However the enemies only spawn on top, bottom, right, and left side. They don’t spawn on points that are located diagonal to the player.
Foreach loop inside the spawnEnemies:
foreach (var enemyGroup in waves[currentWaveCount].enemyGroups)
{
while (waves[currentWaveCount].spawnCount < waves[currentWaveCount].waveQuota)
{
if (enemiesAlive >= maxEnemiesAllowed)
{
maxEnemiesReached = true;
return;
}
Instantiate(enemyGroup.enemyPrefab, player.position + relativeSpawnPoints[Random.Range(0, relativeSpawnPoints.Count)].position, Quaternion.identity);
enemyGroup.spawnCount++;
waves[currentWaveCount].spawnCount++;
enemiesAlive++;
}
}
:: Hi Jason, you can modify your code like this to print out the spawn point that is being used every time an enemy is spawned. This should give you insight into why the issue is occurring:
foreach (var enemyGroup in waves[currentWaveCount].enemyGroups)
{
while (waves[currentWaveCount].spawnCount < waves[currentWaveCount].waveQuota)
{
if (enemiesAlive >= maxEnemiesAllowed)
{
maxEnemiesReached = true;
return;
}
int selectedIdx = Random.Range(0, relativeSpawnPoints.Count);
Instantiate(enemyGroup.enemyPrefab, player.position + relativeSpawnPoints[selectedIdx].position, Quaternion.identity);
print("Selected index: " + selectedIdx + "; spawn point used: " + relativeSpawnPoints[selectedIdx].name);
Instantiate(enemyGroup.enemyPrefab, player.position + relativeSpawnPoints[Random.Range(0, relativeSpawnPoints.Count)].position, Quaternion.identity);
enemyGroup.spawnCount++;
waves[currentWaveCount].spawnCount++;
enemiesAlive++;
}
}
:: I found out why the issue was happening, the points that were placed diagonally were placed farther than despawnDistance.
Advertisement below: