Be the first to post for 'Critical Hit And Weapon Bonus'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

I solved it in fewer lines of code.

private float CalculateDamage()
    {
        float damage = baseDamage + weaponInUse.GetAdditionalDamage();
        bool criticalHit = UnityEngine.Random.Range(0f, 1f) <= criticalHitChance;
        if (criticalHit)
        {
            damage = damage * criticalHitMultiplier;
        }
        return damage;
    }

I believe it reads better too, but I don’t know. Absolutely love this course!

I’ve gone for a different take on critical hits…

Rather than a critical based on the player having a %chance, i based it on the enemy having a certain amount of armour coverage… ie. if 70% of him is covered with armour, then the attack has a 30% chance of ignoring it (my version of a crit).

    private float ApplyWeaponAndArmour(float weaponDamageMod, float armourProtection, bool armourHit)
    {
        float weaponDamage = baseDamage * weaponDamageMod;

        if (armourHit)
        {
            Debug.Log("armour applied: " + armourProtection);
            float damageWithArmour = Mathf.Clamp(weaponDamage - armourProtection, 0f, weaponDamage);
            return damageWithArmour;
        }
        else
        {
            Debug.Log("armour ignored: " + armourProtection);
            unarmouredHitParticleSystem.Play();
            return weaponDamage;
        }
    }

When it comes to player stats/abilities, I can use those to increase the chance of the player successfully targetting an unarmoured area. (and the opposite when being attacked.)

Privacy & Terms