Ok so I have a character that has three attacks, two normal attacks and a special attack, what I want to do is have it randomly choose between the three attacks but have a much lower chance of getting the special attack. I know how to do the random number, but how would I go about doing the chance part? Thanks.
2 Likes
for example:
generate a random number from 0 to 1. If it is < 0.45 normal attack 1, if it is >= 0.45 and < 0.9 normal attack 2. If it is >= .9 special attack
2 Likes
You can get a random value between 0 and 1 and use different intervals of that value to decide between the different attacks.
C# example:
float randValue = Random.value;
if (randValue < .45f) // 45% of the time
{
// Do Normal Attack 1
}
else if (randValue < .9f) // 45% of the time
{
// Do Normal Attack 2
}
else // 10% of the time
{
// Do Special Attack
}
Edit: Not only did you beat me to it, but you even used the same values as I did.
5 Likes
great minds think alike
2 Likes
Thanks a lot works perfect! Can’t believe I didn’t think of that.
1 Like