- Home /
 
Controlling posibilities
Hello everyone,
I am making a platform game and so far I've made 3 power-ups. When the player gets a power-up it is counted and this number is stored. What I want is to increase the posibility for the power-ups that are not picked so often, using this number of course. Any suggestions on how to go on with this?
I could do that for you, but provide an example of your script so the solution I give you will be relevant to what you already have rather writing one from scratch and having a back and forth with you on how to implement my solution into what you are already doing.
Thanks for the reply! I am not really sure how to do it but generally I think that I should have a void method which will take three integers (how many times each of the power-up is taken) and will eventually set the value of a variable to one of the names. Something like that:
 void PickPowerUp(int pow1, int pow2, int pow3){
 
         // $$anonymous$$agic here
 
        selectedPowerUp = "coinDoubler";
 }
                 Answer by pyramidhead01 · Jul 16, 2019 at 07:48 PM
Let me just show you how I might go about this:
 public class PowerUpItem : MonoBehaviour 
 {
     public int timesCalled;
     public int chanceMin;
     public int trueChance;
     public int highChance = 5;
     public int lowChance = 15;
     
     //this is the dice roller for you, wherever you are creating PowerUps, call Chance().
     public bool Chance()
     {
     //This is super rough, I would find somehting better to rate the tiers of timesCalled, but it makes it harder to receive the item per each 5 times it's called the I set up the variables for you.
         if(timesCalled >= lowChance)
         {
             if(timesCalled < lowChance && timesCalled > highChance)
             {
                 if(timesCalled <= highChance)
                 {
                     trueChance = Mathf.RoundToInt(Random.Range(chanceMin, 100);
                     PoweringUp();
                     return true;
                 }
                 trueChance = Mathf.RoundToInt(Random.Range((chanceMin - 20), 100);
                 PoweringUp();
                 return true;
             }
             trueChance = Mathf.RoundToInt(Random.Range((chanceMin - 40), 100);
             PoweringUp();
             return true;
         }
         else
         return false;
     }
     
     public void PoweringUp()
     {
         if (Chance() == true)
         {
             timesCalled++;
             Chance(); //You might not need to call this again, I don't have a compiler and this line may be redundant
         }
     }
 }
 
               I see you marked your response to my answer as the right answer; if I indeed to help you with the solution, can you mark this comment as the best answer? It would be much appreciated and will be more inclined to help you in the future ;)
Thanks for the answer! As mentioned I don't have a compiler, so as I was looking it over I noticed a couple things that would give you issues, I fixed them here, but it still could be a little tighter and would give you a better solution if I could actually test it:
     public class PowerUpItem : $$anonymous$$onoBehaviour 
     {
         public int timesCalled;
         public int chance$$anonymous$$in;
         public int highChance = 5;
         public int lowChance = 15;
         bool chance;
         
         //this is the dice roller for you, wherever you are creating PowerUps, call Chance().
         public void Chance()
         {
         int roll;
         //This is super rough, I would find somehting better to rate the tiers of timesCalled, but it makes it harder to receive the item per each 5 times it's called the I set up the variables for you.
             if(timesCalled >= lowChance)
             {
                 if(timesCalled < lowChance && timesCalled > highChance)
                 {
                     if(timesCalled <= highChance)
                     {
                         roll = $$anonymous$$athf.RoundToInt(Random.Range(chance$$anonymous$$in, 100);
                         if(roll == 100)
                         {
                             PoweringUp();
                             chance = true;
                             return;
                         }
                     }
                     roll = $$anonymous$$athf.RoundToInt(Random.Range((chance$$anonymous$$in - 20), 100);
                     if(roll == 100)
                     {
                         PoweringUp();
                         chance = true;
                         return;
                     }
                 }
                 roll = $$anonymous$$athf.RoundToInt(Random.Range((chance$$anonymous$$in - 40), 100);
                 if(roll == 100)
                 {
                     PoweringUp();
                     chance = true;
                     return;
                 }
             }
         }
         
         public void PoweringUp()
         {
             if (chance == true)
             {
                 timesCalled++;
                 chance = false;
             }
         }
     }
                 Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Random movement script not working C# 2 Answers
Random message generator out of control 1 Answer
Making a camera list 1 Answer