I have two numbers, one steadily increasing, the other is fixed. I'm trying to increase the likelihood of triggering an event as the increasing number gets closer to and surpasses the fixed number.

The chance shouldn't get to 100% no matter how far beyond the increasing number gets, but stop increasing at some point. (if this point is easily adjustable, all the better).

Thanks a bunch for any help as math is not my strong suit.

  • 1
    \$\begingroup\$ What are you expecting from us? \$\endgroup\$ – realUser404 Dec 29 '16 at 9:19
  • \$\begingroup\$ Any help is appreciated, I don't even know what any math term for anything required for such a calculation is. :/ \$\endgroup\$ – JanArve Dec 29 '16 at 14:09

A very quick solution :

If you set the following terms

  • currentValue = the increasing variable, going from minValue to maxValue (and possibily more)
  • minValue = start value of the increasing one
  • maxValue = your "fixed value"
  • minPercent = the minimum % of chance for the trigger (for example 0.25)
  • maxPercent = the maximum % of chance for the trigger (for example 0.95)

then the following pseudo code returns a trigger chance that grows linearly from 0.25 to 0.95 and then stay at this value

if (currentValue <= maxValue)
   // how much are we from the min value (0) to the max value (1) 
   float ratio = (currentValue-minValue)/(maxValue - minValue);
   result = MinPercent + ratio*(maxPercent - minPercent)
    result = maxPercent
  • \$\begingroup\$ Looks like this might be exactly what I need! will check it out properly when I get back home. \$\endgroup\$ – JanArve Dec 29 '16 at 15:46

Your Answer

