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:
if(Random.Range(0f, 1f) < 0.25)
// Spawn node
The problem:
Now I want to balance the number of nodes per phase. To do this, I have these variables:
- TotalNodesToPut
- NodesPut
- NodesLeftToPut
- PhaseProgress (0.0-1.0 normalized percentage of progress)
My plan was, to have the base chance of spawning a node to be 50%, and then 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. So I thought this would do the trick:
if(Random.Range(0f, 1f) < 0.5f + ((PhaseProgress - (NodesLeftToPut / TotalNodesToPut)) - 0.5f))
But, to take a simple example, where we’re halfway through the phase, and have placed half the nodes, so we should end up with 0.5:
0.5f + ((0.5 - (10/20)) - 0.5f) = 0
This is only one of the hundreds of different ways I’ve tried and failed. I thought I had it dozens of times, but then something went wrong at the end or beginning of the phase, or the modulation percentage was way too low or something.
It seems like a simple task, but I just can’t get it to work I have tried searching on the web, but haven’t found anything about this particular problem. Any help is much appreciated!