I've been struggling with this for over a day now. What seemed a simple task, has just wrecked me. I hope someone here can help me figure out what I'm missing. Please, please help me :)
The functionality I need:
Think of my game as Guitar Hero, but instead of pre-placed nodes, I place the nodes randomly as the game progresses, at certain valid points in time. Now, instead of relying on randomness alone, I've made phases of difficulty, where I set a certain number of nodes to be spawned throughout the phase, and I'd like to have those evenly distributed within the phase. Since it's an arcade/highscore game, it needs to be roughly the same number of nodes placed every time you play the game, but the nodes should be placed differently each time. Until recently, I simply had something like this code, called for each valid point in time:
if(Random.Range(0f, 1f) < 0.25) // Spawn node
Now I want to balance the number of nodes per phase. To do this, I have these variables:
- PhaseProgress (0.0-1.0 normalized percentage of progress)
My plan was, to have the base chance of spawning a node to be 50%. I would then like to modulate that down to 0% and up to 100% depending on how many nodes still need to be put down, and how far we have progressed through the phase. It should be so that the percentage of nodes put down follows the progress percentage. If we have spawned 5 of 20 nodes (25%) but have progressed 75% of the phase, the chance to spawn a node should be really high. If we have spawned 15 of 20 nodes (75%) but have only progressed 25% of the phase, the chance to spawn a node should be really low.
It seems like a simple task, but I just can't get it to work :( I've tried dozens of things, started over again and again, and it's just never right, which is why I'm hesitant to show any code. I wouldn't want to start people off on the wrong foot. I have tried searching on the web, but haven't found anything about this particular problem. Any help is much appreciated!