Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Evasion and Critical Chance

Discussion in 'Game Design' started by Not_Sure, Feb 24, 2015.

  1. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Hey everyone,

    So I'm still working on an ARPG engine as a side thing and I have the basis of where I'd like to be. Right now I'm looking at how to calculate chance to evade and chance to critical.

    The chances will be derived from two numbers, the attacker's "balance" and the defender's "balance". I gues you could also call it "attack class".

    Both of these numbers are dynamic and are constantly shifting frame to frame. It's one of the core mechanics of the engine, really. The characters have a pool that increases max balance as they level up, then the current balance moves based on things such as fatigue, attacking, or being hit.

    I know that I always want there to be a chance to hit, a chance to evade, and a chance to critical. And I think that I would like chance to score a normal hit to be the highest when the balances are tied.

    To do this I was looking at doing the difference as a linear function of a cubed root to make an "s" shape:
    So something like:
    (attackerBalance - defenderBalance)^(1/3)

    Trouble is, that's WAY to much math to do multiple times a frame.

    So I think I need to do something simpler.

    Any suggestions how I can get a chance for evasion, critical, and normal hit from two values, while making sure that all three are always possible?

    Thanks for any suggestions.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Pshaw. No it's not. Compared to the math going on every frame in any action game (even something like a physics-based platformer), this is so trivial as to be completely insignificant. Or is it so insignificant as to be completely trivial? Either way, you're making major mountains out of molehills, here.

    So if that's the equation you like, I say go for it.

    I'll only add that you could also consider the sigmoid function, which it often used in neural networks but also has a million and one other uses around the home.
     
    Martin_H, HolBol, CDMcGwire and 6 others like this.
  3. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Really?!!

    I guess I should have tried to punch it up and stress tested it before posting.

    Also, thanks for the suggestion on doing a sigmoid function. That does look a lot closer to what I'm going for. (I kinda suck at algebra and college math is a bit hazy).

    Thanks Joe!
     
  4. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    If by multiple you mean 1,000 times... maybe. Otherwise, it's fine.

    Something else you can do, which I find works great... rather than trying to find the exact mathematical function.

    Just make a public AnimationCurve, shape it to be the exact response curve you want... and then call AnimationCurve.Evaluate.
     
  5. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Can you simplify your combat system? Modern RPG's often use simple combat systems that are easy for players to understand. You can probably scrap the whole thing and go with: Armor Value vs Attack Damage. Not only is that easy to understand, trivial to implement, and flexibly agile for game balance; it is also nicely scalable as you add and remove content.

    As for critical hits, dodges, and evasions, I've seen far too many AAA post-mortems saying they wish they'd never added them. I'd NOT add them until much later. Same argument for % dmg/healing and triple for complete healing. /Shiver.

    PS - Premature optimization is the antidote to shipping. Not doing it turns out to be a sign of wisdom.

    Gigi
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    The square root gets a bad rep because it's used for distance checking, distance checking can be done hundreds of times per frame.

    If you are really worried about the root you can use a polynomial. Across a limited range a polynomial can match any function. Just benchmark and profile it first before you do anything drastic.

    Preoptimisation is evil. No point destroying code readability to make something fast that only ends up happening three times a game.
     
  7. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    This is not a bad idea. Thank you, I'll give it a try.

    Well the two issues I have with that are:

    1) This is a pipe dream side project, not my current core project. I'm not really looking to ship and realistically I know that the total scope of it is at least $1M. Total pipe dream right now.

    and

    2) The balance system I'm talking about is a MASSIVE theme of the engine. The whole point of it is so that I can put an emphasis on enemy numbers playing a huge role in combat, rather than diablo's "mow em down" approach. That and it's what distinguishes DEX from STR and INT.

    STR and INT boost physical and magical resistances respectively. DEX on the other hand adds to the balance which influences evasion chance for its defensive characteristics. Without evasion, it looses that.

    I get what you're saying though and the advice is welcome, I'm just not sure that I can abandon it since it's one of the game's central hooks.

    EDIT: And yes, user readability is a HUGE concern of mine. I'm wondering if some of my ideas are too far from convention to be approachable. But that's for another thread, and only with something to show.
     
    Last edited: Feb 25, 2015
  8. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    From a purely design standpoint, why do you want critical hits/evasion-dodging? Is it because other games have them, or because it helps your game?

    Critical hits are pretty much a randomized boost in a single attack, which - randomly - drops an entity's time to defeat. Dodges/Evasion are the counter to that - a randomized increase in an entity's time to defeat. While this is obvious - you seem to have played a RPG or two in your time - the randomization is what gets my attention. It's a roll of the dice, which isn't a bad thing; D&D has done similar things for decades and players are OK with it. The problem is, it takes a factor out of the player's hands. Are you absolutely sure you want this?*

    Me being me, I've grown to dislike random factors in games; I find myself gravitating towards giving the player a check of personal skill (as in, the player, not their character.) As much as Quicktime Events can be reviled, in an RPG I find they can be helpful, as instead of the "DM" making an arbitrary roll you have no control over, instead the player can exhibit some skill (e.g. reflexes, or basic pattern recognition, or whatever) to influence the course of the larger event going on.

    Also, I feel less reliance on randomness helps the RPG be better-received; one thing people don't like is to be able to fail for reasons outside of their control. You know the Magus boss fight in Chrono Trigger, in 600 A.D.? I always consider the "Dark Matter" attack in the second phase - It's already a 'wipeout' attack meant to seriously injure or out-and-out kill some party members. What if it could crit? The fight is intended to be hard, but a critting Dark Matter would be a "B.S." kill. As it stands in the current game, you're A) expected to be a high enough level, which the game is carefully crafted to allow you to easily be, and B) you're expected to figure out that the correct reponse is healing ASAP to overcome this spike damage, as by that point in the game, you've already been exposed to bosses with an "Attrition-Spike" damage pattern, where if you don't heal out the spike damage, someone dies, which is bad because that affects your DPS and TTD in favor of the enemy, not the player.

    The fact that you're removing stat(s) from your game's design is a nice, productive bonus in my opinion.

    *: This is a sincere question, not a rebuttal. Some gamers enjoy rolls of the dice, or flips of the coin. Others don't. Will the type of gamer you're building this game for like the randomness?
     
    Last edited: Feb 25, 2015
    GroznyBear and Gigiwoo like this.
  9. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    @Asvarduil - That's the thing, it's not really random. I mean there is a percentage of chance that there will be a critical, but that percentage is tied into a central mechanic.

    I really wasn't wanting to go into it because I'm trying to be more "put up or shut up" with my posts, but I guess it needs further explanation.

    All the enemies haracters have a stat called "balance". This stat drops when you get hit or when you attack. The more strength based the hit, the more it drops. This means that a barbarian type character would be great at jumping into crowds and knocking them around, keeping them off balance. Then a dexterous character, such as an assassin, would be great at doing massive damage to single targets, but would suck in a crowd.

    So what I'm trying to do is give each character type its own flavor and gameplay, rather than spamming numbers. And I want the player engaged, rather than just spamming skills. And I want a lot of risks being weighed in on at all times.

    Part of that has to include the surprise of suddenly getting whacked and having to adapt for it.
     
    AndrewGrayGames likes this.
  10. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    @Not_Sure - Have you heard of 'Yes And'? It's the opposite of both 'Yes But' and 'No!' @Asvarduil offered really great feedback on issues with your design - solid ideas that could make your design stronger, funner, and easier to implement.

    If you want to strengthen both this design and your skills as a designer, you might consider coming at this differently. You could start with the premise that your idea is massively flawed. That way, every interaction with another designer creates an opportunity to find the weaknesses and improve it. 'Yes And' is great for that.

    Gigi
     
    AndrewGrayGames likes this.
  11. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    That's well and good; rolling a stat is the primary RPG mechanic. As I said before, there's nothing wrong with that, and it doesn't cheapen the design you're working for. My suggestion was only to consider how to execute it such that the player - or the enemy - does not have what a player would consider an "unfair" advantage.

    Let's go further back, beyond JRPGs. Let's go to Super Mario Bros. for the NES. The whole game is skill-based; there's no randomness to speak of. Every challenge in the game was created and put in a level ahead of time. When you close on the first question block in World 1-1, the Goomba will always appear in the same spot. Period.

    Yet, that game is built entirely around risk/reward decisions.

    The word "risk" does not always imply "use of a random number generator;" this is something we who are RPG enthusiasts typically interpret it to mean, because we expect the rolling for a stat as a game's primary mechanic. In fact, most of the time, that is the primary mechanic behind an RPG, according to the D&D Dungeon Master's Guide (if you want the page number...I might add it sometime.)

    No, what "risk" actually means is "exposure to the chance of injury or loss; a hazard or dangerous chance."* It's not that a dice gets rolled that can make you fail, it's the point that you can fail, or experience a negative condition in the first place.

    Merely having battles - or, any failable event - in your game is exposing your players to risk, that to continue they must overcome. You've already got risks in your game. Putting my previous question about the design of a RNG-driven crit mechanic in a different way: are you putting this crit mechanic in because you feel your design lacks sufficient risk to the player to be engaging? If so, is RNG and an accompanying stat the answer, or is there a possibility that a different, but better, answer exists that would suit your game better?

    You could always simply tune your encounters to feel more dangerous, or create more sinister assets to sell a feeling of tension, or create a mechanic that if failed simply doesn't give the player as much of an edge as they might enjoy.

    Never
    punish the player.


    *: I know the word 'chance' is in that definition; despite this, there's plenty of real-world examples of a failure condition not being tied to luck in the slightest, that still count as risks. Crossing a street in Austin is perhaps a perfect example.
     
    Last edited: Feb 26, 2015
    Gigiwoo likes this.
  12. CDMcGwire

    CDMcGwire

    Joined:
    Aug 30, 2014
    Posts:
    133
    I find it interesting that math was the easiest question to answer in this thread, and immediately turned to "should there be math here?" I should have started looking at these forums sooner in life.

    ON TO MY OPINION!!! :D

    You are making an Action RPG. In my many years of grinding through Torchlight/Diablo/Borderlands/League of Legends/Titan Quest(hue) it has been my experience that dodge chance is unrewarding. Only in the most extreme circumstances do you see its effect (I.E. 90-100%). It's unengaging, as it is passive, even if you can use tactics to increase its effect. And there are so many other, more engaging ways to implement mobility based defenses in a genre in which a defining feature is that it is an RPG where your feet aren't magnetized to the ground. Also, keep in mind that a player focused on dodge chance will likely either:

    1.) Be really squishy

    2.) Be not so squishy

    In case 1, all deaths will be frustrating and induce save scumming type behavior or ditching the play style for something reliable.
    In case 2, the player will be even harder to kill, making balance a pain in the rear.

    I really like your idea of balance a factor of combat! :) Its not something taken into account often in games. My point is that you should try to implement it in a more tactile, readable way. As far as stats go, instead of balance-loss decreasing your dodge chance/crit chance, it could: decrease movement speed, attack speed, and defense; reduce shield effectiveness; increase flank damage; things to that nature.

    Should all randomness be removed? Heck no. Random is fun. But getting killed by a traffic cone someone accidently launched with an explosive is random and fun. Arbitrarily missing a perfectly lined up headshot because math, is not fun.

    I know I'm drawing parallels from First Person Shooters, but my point is, in action games there should already enough chaos going on from the components interacting with each other. Arbitrary randomness is unnecessary as a core mechanic.

    Makes for some hilarious rare item types, however.
     
    Gigiwoo and AndrewGrayGames like this.
  13. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Indeed! The +5 Llama Suit of Eye-Laser Shooting (wearing it lets your shoot lasers from your eyes) is a testament to this. ;)
     
    Gigiwoo likes this.
  14. CDMcGwire

    CDMcGwire

    Joined:
    Aug 30, 2014
    Posts:
    133
    Am I allowed to put that in every game I ever make, ever? Because I might.
     
  15. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    I think you should. I'd enjoy it.
     
  16. Atmey

    Atmey

    Joined:
    Nov 3, 2012
    Posts:
    88
    Reminds me of Fire Emblem Biorythm

    It is basically the same thing, the higher it is, the more llikely you are to score crits or evade.

    If you are really worried about calculations every frame, just calculate it when needed (when displaying or attacking) there also option to call it once every second by using StartCoroutine
     
  17. GroznyBear

    GroznyBear

    Joined:
    Oct 16, 2015
    Posts:
    4
    You are AWESOME!
    /*found a very useful advice and new 'small feature'*/
     
  18. DominoM

    DominoM

    Joined:
    Nov 24, 2016
    Posts:
    460
    Here's my no curve take on it.. I assumed stats are percentile.

    Code (csharp):
    1. dodgeChance = -45;
    2. criticalChance = 45;
    3. randomChance = 50;
    4. random = Random.range(-randomChance, randomChance);
    5. if (random < dodgeChance) {
    6.     dodgeEffectiveness = random + (defenderBalance / numberOfAttackers) - attackerBalance;
    7.     // opponent dodges from 'just avoided' to 'positioned for counter attack' depending on effectiveness
    8. } else {
    9.     result = random + attackerBalance - (defenderBalance / numberOfAttackers);
    10.     if (random > criticalChance) {
    11.         // critical with result effectiveness (from slow bleed out to instakill)
    12.     } elif (result <= 0) {
    13.         // opponent dodge, parry or armour block with -result effectiveness
    14.     } else {
    15.         // hit with result effectiveness
    16.     }
    17. }
    This is more for a test on trigger than a frame by frame check though. It'd be used to set the player and opponents next animation cycles when attack button pressed.

    I wouldn't personally have an always chance of critical / dodge (fumble?) but base them on testing against result instead of random. That way the chances of critical and dodge automatically adjust to differences in abilities with a big negative result being a fumble, and large positive being a critical.
     
    Last edited: Apr 10, 2017