I am working on a rpg game and it goes betther then expected ![]()
but I noticed a critical problem whit the AI when I did some testing: The enemy uses two attacks when it is using a spesific move. I would guess I have written something wrong in the function that picks the attack, but I can’t find it…
Note: I’m not including the entire script, but the only part missing is some vars and other things that’s not important to the problem
Note2: written in javascript
//Varibles used for random numbers
var ChanceForCrit;
var AttackPicker;
function UpdateRandom () {
//Set a random number between 1 and 100 giving 1/100 for each number
ChanceForCrit = Random.Range(1, 100);
AttackPicker = Random.Range(1, 100);
Debug.Log("AttackPicker = " + AttackPicker + " ChanceForCrit = " + ChanceForCrit);
}
function EnemyAttack () {
UpdateRandom();
if (AttackPicker < 20) {
//problem right here: it uses rage AND bite when it's using this attack
AtkRage();
}
if (AttackPicker > 20){
AtkBite();
}
}
//List of attacks
//----------------------------------------------
function AtkBite () {
var AttackPower = MouseAtk * 10 / 50;
UpdateRandom();
//Check for crits
if (ChanceForCrit < 10) {
//It's a crit, double the damage
AttackPower = AttackPower * 2;
//Inform the player
BattleGUI.BattleInformation += "\nMouse used bite\nIt's a critical hit! Did " + AttackPower + " damage!";
}
else {
//It's not a crit :'(, don't do anything
//Inform the player
BattleGUI.BattleInformation += "\nMouse used bite\nDid " + AttackPower + " damage!";
}
Arnold.ArnoldHp -= AttackPower;
}
function AtkRage () {
var AttackPower = MouseAtk * 20 / 50;
UpdateRandom();
//Check for crits
if (ChanceForCrit < 10) {
//It's a crit, double the damage
AttackPower = AttackPower * 2;
//Inform the player
BattleGUI.BattleInformation += "\nMouse used rage\nIt's a critical hit! Did " + AttackPower + " damage!";
}
else {
//It's not a crit :'(, don't do anything
//Inform the player
BattleGUI.BattleInformation += "\nMouse used rage\nDid " + AttackPower + " damage!";
}
Arnold.ArnoldHp -= AttackPower;
}
thanks in advance ![]()