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?
Jump to content
Posted 09 May 2014 - 11:31 AM
crit_chance = 0.05 if rand_float(0,1) < crit_chance damage *= 1.5For 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.0675EDIT: Juliean is correct, I done goofed.
Edited by fastcall22, 09 May 2014 - 12:12 PM.
gzip: H4sIAAAAAAAEAG1QTUvEMBC991e8nvaiFfYoS7yo sLCo6MnjtJ1ugmkiyWRL/72z3T1YEQIJ8z4zA2Xp yPvt1qBpGrRFIJZkk9FyRyUzHCbKIHgn4hnZOrm1 TD0mG0HCCs+QGDGWziKXI6Wm2n++GYwUVH2mrGEE PnGCVQ8K8+JYfXA6URDEQfMZh5h6g5eoAlWJdeEI bbH2qYZf7XMUfw8f/Q0oMeZYNL9/WHF0uFEshvMr XYujd9SycFb+F18QcSOvlJauZ8ejqevdnV7/d550 e0t6prmunh73Bu+vz4c/XUeOQXfJgvKNkhf95U8/ Dtgmy5IBAAA=
Posted 09 May 2014 - 11:55 AM
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?