I am trying to create a method I can use that will calculate a chance for my game.
For example: When the player reaches level 25 a certain thing unlocks, once they are level 225 (the max for this skill) I need it to say there is a 25% chance of the event happening.
I need a method so I can plugin the required level, max level, current level, and max chance and calculate their current skill which needs to be a constant variable but is the variable itself at level 25 and then equals 25% at level 225
I tried using
maxChance * (currentLevel - requiredLevel) / maxLevel - requiredLevel
but this method is giving the 25% chance at level 224 when it should be at 225.
I thought since the variables are 200 numbers across it could give a nice user friendly value but it seems to stop at 224.
Note: I am using percentages as decimals so .25 = 25%. Also my explaining might seem complicated because I am confused myself, if needed I can try to explain this better.
Note that you have 201 (not just 200) numbers: At level 25 the chance increments from 0 to X. Then at each of the subsequent 200 levels it increments by X again. So you need
X * 201 = maxChance
or, using the requiredLevel
and maxLevel
:
X * (1 + maxLevel - requiredLevel) = maxChance
thus
X = maxChance / (1 + maxLevel - requiredLevel)
Then for currentLevel
the chance is
chance = max(currentLevel + 1 - requiredLevel, 0) * maxChance / (1 + maxLevel - requiredLevel)
= max(currentLevel + 1 - 25, 0) * 0.25 / 201
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.