Spawn specific proportion of attackers rather than random

Hi all,

Rather than spawning random attackers, I am hoping to spawn a specific proportion of attackers (e.g., 80% lizards, 20% foxes) but am not sure how to go about doing this. Just wondering whether anyone is able to help me out with this particular problem.

Cheers
Lana

Hi,

That is very simple. Much simpler than our current solution. Take a look at the Spawner class. How do we spawn attackers at the moment?

Hi Nina, thanks for your prompt reply.
At the moment we are spawning attackers using a variable (attackerIndex) which generates a random number corresponding to an attacker within the array of attackers.

I am not sure how to specify certain proportions for each attacker in the attacker array though.

Do you want to keep the array? If not, you could replace the array with a normal variable, assign an attacker to it and spawn that one attacker. This random stuff associated with the index would not be needed anymore.

Yes, I would like to keep the array so that I have an array of attackers (or items) but spawn them based on a set proportion e.g., having that array of attackers (foxes spawn 80% of the time, lizards spawn 10% of the time, and something else spawns another 10% of the time, for example). Is there any way to do this?
Thanks for your help in advance!

Theoretically, this should be possible. Maybe like this:

float value = Random.value;

if (value < 0.1f)
{
    // spawn index [0]: lizard
}
else if (value < 0.9f) {
    // spawn index [1]: fox
}
else 
{
    // spawn index [2]: something else
}

I don’t know if this represents the actual probability but you can certainly do some research and modify the if-conditions.

Thanks very much for your help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms