Hello, I am creating a Smash Bros like fighting game and the AI is attacking correctly. However, I another character successfully hits them in the startup-lag of the attack, they complete the attack regardless. This gets especially annoying if the other character grabbed them.
Interrupt Snippet
function InterruptAllAttacks () {
Debug.Log(gameObject.name + " Was Interrupted.");
animation.Stop();
GetComponent(SpecialController).InterruptSpecialAttacks();
GetComponent(GrabAndThrow).StopAllCoroutines();
GetComponent(FighterControllerNew).canMove = false;
if(GetComponent(AI)) {
GetComponent(AI).CancelInvoke("CheckAttack");
GetComponent(AI).checking = false;
}
GetComponent(AttackControllerNew).StopAllCoroutines();
}
AI Attack controls
function CheckAttack () {
checking = true;
var pos = transform.TransformPoint(forwardHitPosition);
var pos2 = transform.TransformPoint(upwardHitPosition);
var pos3 = transform.TransformPoint(downwardHitPosition);
var pos4 = transform.TransformPoint(backwardHitPosition);
var enemies : GameObject[] = GameObject.FindGameObjectsWithTag("Hurtbox");
for (var go : GameObject in enemies) {
var enemy = go.GetComponent(Hurtbox);
if (enemy == null)
continue;
if(enemy.num == attacker.playerNo) {
continue;
}
if(enemy.type == "Item") {
continue;
}
var rand = 0;
var num = 0;
var otherNum = 0;
if(rand == 0) {
if (Vector3.Distance(enemy.transform.position, pos) < forwardHitRadius)
{
if(!attacker.busy && controller.OnGround()) {
num = Random.Range(0, 5);
var forwardAttacks : String[] = ["normalA", "sideTilt", "sideSmash", "downTilt", "downSmash"];
attacker.Attack(forwardAttacks[num]);
} else if(!attacker.busy) {
attacker.Attack("forward");
}
}
if (Vector3.Distance(enemy.transform.position, pos2) < upwardHitRadius)
{
if(!attacker.busy && controller.OnGround()) {
otherNum = Random.Range(0, 2);
var upwardAttacks : String[] = ["upTilt", "upSmash"];
attacker.Attack(upwardAttacks[otherNum]);
} else if(!attacker.busy) {
attacker.Attack("upward");
}
}
if (Vector3.Distance(enemy.transform.position, pos3) < downwardHitRadius)
{
if(!attacker.busy && controller.OnGround()) {
} else if(!attacker.busy) {
attacker.Attack("downward");
}
}
if (Vector3.Distance(enemy.transform.position, pos4) < backwardHitRadius)
{
if(!attacker.busy && controller.OnGround()) {
attacker.Attack("downSmash");
} else if(!attacker.busy) {
attacker.Attack("backward");
}
}
}
}
yield WaitForSeconds(waitTime);
checking = false;
}
Any an all help is much appreciated.