Name: Anonymous 2011-09-03 18:17
Pic:
http://i56.tinypic.com/szeerr.jpg
tl;dr:
How to work a function which produces the desired ditribution - approximated in the grey graph half way down the image
Text:
Hypothically this is regarding a scrolling shooter, I'm writing some code to control the spawning of powerups. Every (dist) units travelled, i perform a roll using RNG.
First part of pic shows this code. Using conditions to process the result of the roll, 70% of the time no powerup is spawned, the remaining 30% is divided equally into 4 types of powerup. But I want the chances for each powerup type to change, depending on (dist), illustrated in the graph
Assuming 14 types of powerup, only 7 have a chance to spawn at the start, but as the player progresses, those sterter powerups will appear less often, and by the end he sees a different set of 7.
So i figured i need a function to control the x<RanValue<y Conditions, driven by both an ID assigned for each type of powerup, and (dist).
I assumed it would look something like the grey graphs, and i guessed from the start-of-game line and end-of-game line that a Sine/cosine function would fit the purpose.
Final graph shows a quick attempt,
(cos(0.19x)*0.5)+0.5
This appears to result 1 with an ID of 0, and 0 with an ID of ~16 (may change the number of powerup types)
It'd also be easy to add dist) in
(cos(0.19x + f(dist))*0.5)+0.5
where f(dist) is some function to condense the maximum range of (dist) into a radian
Where im stuck is making the cosine function 'pinch' at the top, to closer resemble the faked curve in the grey graph.
Is Cosine the best fit for my need, or should i go to something else (normal, gaussian bell curves)?
http://i56.tinypic.com/szeerr.jpg
tl;dr:
How to work a function which produces the desired ditribution - approximated in the grey graph half way down the image
Text:
Hypothically this is regarding a scrolling shooter, I'm writing some code to control the spawning of powerups. Every (dist) units travelled, i perform a roll using RNG.
First part of pic shows this code. Using conditions to process the result of the roll, 70% of the time no powerup is spawned, the remaining 30% is divided equally into 4 types of powerup. But I want the chances for each powerup type to change, depending on (dist), illustrated in the graph
Assuming 14 types of powerup, only 7 have a chance to spawn at the start, but as the player progresses, those sterter powerups will appear less often, and by the end he sees a different set of 7.
So i figured i need a function to control the x<RanValue<y Conditions, driven by both an ID assigned for each type of powerup, and (dist).
I assumed it would look something like the grey graphs, and i guessed from the start-of-game line and end-of-game line that a Sine/cosine function would fit the purpose.
Final graph shows a quick attempt,
(cos(0.19x)*0.5)+0.5
This appears to result 1 with an ID of 0, and 0 with an ID of ~16 (may change the number of powerup types)
It'd also be easy to add dist) in
(cos(0.19x + f(dist))*0.5)+0.5
where f(dist) is some function to condense the maximum range of (dist) into a radian
Where im stuck is making the cosine function 'pinch' at the top, to closer resemble the faked curve in the grey graph.
Is Cosine the best fit for my need, or should i go to something else (normal, gaussian bell curves)?