Jump to content
  • Advertisement
Sign in to follow this  
Meiji

Percentage of chance

This topic is 1678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

So I'm working on a game using HeroCloud, and I have a question. There's a character with, say, 5% chance to hit his target critically. How do I accomplish that he actually has 5% chance to do something? 

Share this post


Link to post
Share on other sites
Advertisement
Not sure about HeroCloud, but generally you get a floating point number between 0 and 1, and test if it's equal to or lower than 0.05:
crit_chance = 0.05
if rand_float(0,1) < crit_chance
   damage *= 1.5
For a more "natural" random, you increase the 5% chance by some rate for every failure and reset it when it succeeds:
if rand_float(0,1) < (crit_chance + error)
   damage *= 1.5
   error = 0
else
   # Increase chance by 6.75%
   error += crit_chance * 0.0675
EDIT: Juliean is correct, I done goofed. Edited by fastcall22

Share this post


Link to post
Share on other sites

@fastcall22:

 

Does this code really do what you expect of it? You are adding crit-chance * 1.0675 to the error everytime, which will increase the chance of success rapidly (100% on the first failure, etc). Didn't you mean

   # Increase chance by 6.75%
   error += crit_chance * 0.0675f;

or something along those lines?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!