Search Unity

Damage / Defense damage system

Discussion in 'Scripting' started by hublard, Dec 2, 2016.

  1. hublard

    hublard

    Joined:
    Aug 19, 2015
    Posts:
    79
    Hello there.

    i have a question. i programming a rpg right now. there are different values like strength, dexterity, intelligence
    weapons with different damage.

    for damage output i got one variable -> damageAttack

    for the enemy i have one varibble for defense -> enemyDefense

    now i buildet a formule to manage this. the goal was if a new player with less attack damage fight against a good player with huge defense still do damage. my first formula was

    damageOutput = damageAttack - (enemyDefense / 10)

    the problem is like writen before. if a new player fight against a good one.

    For example de attacker got attack value of 2, the defender a armor value of 50

    calculated -> damageOutput = 2 - (50 / 10) = -3

    so de attacker mack -3 damage. thats not the goal i want.

    so i created i limes graph (attached file)

    like that:

    damageOutput = damageAttack ^ (-(enemyDefense / 100) * 0.3) * damageAttack ;

    this formula works great in excel

    lets try with some values

    Attack = 2
    Defense = 50

    damageOutput = 2 ^ (-(50/ 100) * 0.3) * 2 = 1.8



    i tryied to add this formula to unity but it doesn work.

    can someone help me? unity dont accept this symbol ^ so what i have to do?

    mathf.pow or mathf.exp?


    im really thankful if someone can help me.
     

    Attached Files:

  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Code (CSharp):
    1. Mathf.Pow(damageAttack, (-(enemyDefense * 0.01f) * 0.3f)) * 2