Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sliders representing spawnrate

Started by Andos Jul 30, 2006 at 9:25 PM 4 replies 950+ views
Original Post
Andos
Andos
Hi there. In a 2D game of mine, I want to give the level designer (through the level editor) the ability to set the spawnrate of various game items using some sliders going from 0 to 100. How could I display an actual percentage chance that each specific object will spawn? Example: There are 6 items spawnable, all sliders are at the same position so all objects would have approx 17% chance of spawning. But if all sliders are down at 0% ecxept one, no matter what value it has (other than 0 of course) it would have 100% spawnrate. Currently I can't really see how to do that because the sliderbar's value (0-100) can't directly be used as the spawn chance, the chance depends on the other slider's values as well.
Ultimape
Ultimape
int spwan1;
int spawn2;
int spawn3;
float spawnchance1
float spawnchance2
float spawnchance3

switch (spawn1+spawn2+spawn3){
case spawn1:
spawnchance1=1.0;
break;
case spawn2:
spawnchance2=1.0;
break;
case spawn3:
spawnchance3=1.0;
break;
default:
spawnchance1 = (spawn1+spawn2+spawn3)/(float)spawn1;
spawnchance2 = (spawn1+spawn2+spawn3)/(float)spawn2;
spawnchance3 = (spawn1+spawn2+spawn3)/(float)spawn3;
break;
}


(if all the spawns added up to a specific spawn, then that must be the only spawn with a non zero value, asuming range 0-100, so set that to 100% chance. else modulate the spawn chance based on the values.)

(ps. assumed that 100% case only happens when all but one spawn is 0)
okonomiyaki
okonomiyaki
You have to add constraints to the sliders. Since all of them have to add up to 100%, if one goes down, another one has to go up. Reminds me of Oblivion's freakin' difficult character creation, because you change one slider and it screws with all the other sliders to make sure the model stays in tact...

Anyway, it may be hard to choose which sliders go up when one goes down. You could move all the others up a little when one goes down, and let the user lock sliders to enforce that percentage.
Andos
Andos
Hi people, I actually found out using another method. And it completely goes around the "Oblivion" annoynace that you talked about.

I have six sliders from 0-100:

TotalValue = ObjectA + ObjectB + ObjectC + ObjectD + ObjectE + ObjectF

A_Chance = ObjectA / TotalValue * 100
B_Chance = ObjectB / TotalValue * 100
C_Chance = ObjectC / TotalValue * 100
D_Chance = ObjectD / TotalValue * 100
E_Chance = ObjectE / TotalValue * 100
F_Chance = ObjectF / TotalValue * 100

It works brilliantly and no sliders are moving without I control it. Their percentage can change when the sliders change though, but you have far better control over how often an object will spawn in comparison to another. If they have the same position on the slider-bar, those two objects will have the same spawnchance no matter what, even though other objects can change that spawnchance.
okonomiyaki
okonomiyaki
Quote:
Original post by Andos
Hi people, I actually found out using another method. And it completely goes around the "Oblivion" annoynace that you talked about.

I have six sliders from 0-100:

TotalValue = ObjectA + ObjectB + ObjectC + ObjectD + ObjectE + ObjectF

A_Chance = ObjectA / TotalValue * 100
B_Chance = ObjectB / TotalValue * 100
C_Chance = ObjectC / TotalValue * 100
D_Chance = ObjectD / TotalValue * 100
E_Chance = ObjectE / TotalValue * 100
F_Chance = ObjectF / TotalValue * 100

It works brilliantly and no sliders are moving without I control it. Their percentage can change when the sliders change though, but you have far better control over how often an object will spawn in comparison to another. If they have the same position on the slider-bar, those two objects will have the same spawnchance no matter what, even though other objects can change that spawnchance.



That's a good solution, but realize that you are still sliding the sliders around. Just not visually. When you change one slider, you are changing the values of all the others. As long as you print the real Chance value (calculated by your algorithm) beside each slider, that should work great. I wouldn't display the value of just that slider though, because it doesn't make send for all sliders to be up and every one say they have a 100% spawn chance.

The other thing is that the user doesn't have the option to "lock" a slider. What if they always want one to have a 17% chance of spawning, no matter what the other sliders are at?
Andos
Andos
Yeah you are correct but I think I mentioned that.
What is important in this game is that you can control how much they spawn in comparison to each other, the percentage value isn't that important then. What matters is that you can visually see which object will spawn most frequently which is really easy with this method. The percentage values below the sliders are just for guidance.

But still thanks for your input.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.