Critical chance system

Hello, i try make some critical chance system :

    float randValue = Random.value;
    if (randValue < .90f) // 90% of the time
    {
        // Do Normal Attack
    }
   
    else // 10% of the time
    {
        // Do Normal Attack x 2
    }

Actually my Critical Chance are 10% , But I don’t know how to increase Critical Chance.
For example, if i do a skill system, how could I raise 5% (so 15% total) my critical chance ? I don t know how to change variable, how creta logic system…

I guess it is simple for some of you, but i’m really noob…

Thank’s for any help :wink:

float target = 0.1f; // replace value with chance calculation
float randValue = Random.value;

if (randValue < (1f-target)) 
{...

Something like this would work:

float critChance = 0.0f;

void IncreaseCritChance(float critInc)
{
     critChance += critInc;

     //Never let the crit chance go out of range
     if(critChance > 100.0f)
     {
          critChance = 100.0f;
     }
}

void DoAttack()
{
     float randValue = Random.value;
     if(randValue < critChance)
     {
          //Do crit attack
     }
     else
     {
          //Do normal attach
     }
}

This is obviously sudo code, but you can get the gist :slight_smile:

1 Like

Okay ! Many Thank’s for quick answer, very helpfull :wink: