Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ExplodingCookie · Jun 02, 2013 at 12:32 AM · aiattackfailureinterrupt

StopAllCoroutines not interrupting an AI attack.

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hiddenspring81 · Jun 02, 2013 at 07:53 PM 0
Share

What's the name of the Coroutine that you're trying to stop?

avatar image Jamora · Jun 02, 2013 at 08:06 PM 0
Share

Coroutines are run on the GameObject that started it. Are you trying to cancel the coroutines in the same GameObject that started it?

avatar image ExplodingCookie · Jun 02, 2013 at 08:12 PM 0
Share

The AI Script is calling the Attack function on the AttackControllerNew. Both these scripts are attached to the AI GameObject. The Interruption is called when the DamageAnd$$anonymous$$nockback attached to the AI GameObject Receives knockback from a different Object(Player, Bomb, Spike Trap, ect). Note that I am using JavaScript.

avatar image ExplodingCookie · Jun 02, 2013 at 08:13 PM -1
Share

@hiddenspring81 I am trying to interrupt this function in the AttackControllerNew

 function Attack (attackToUse : String) {
     busy = true;
     var adding = "";
     if(!controller.OnGround()) {
         adding = "Arial";
     }
     lastAttackPush = Time.time;
     if(adding == "") {
         controller.can$$anonymous$$ove = false;
         controller.HaltHorizontal();
     }
     if(GetComponent(AI)) {
         GetComponent(AI).waitTime = animation[attackToUse + adding].length;
     }
     currentAttack = attackToUse;
     Debug.Log(currentAttack);
     animation.Play(attackToUse + adding);
     var initialDelay = DefineWait(attackToUse);
     var hitContainer = DefineHitContainer(attackToUse);
     var timeWait = DefineDelay(attackToUse);
     yield WaitForSeconds(initialDelay);
     for(var hit : Hit in hitContainer) {
          hit.CreateHit(possibleHurtboxes);
          yield WaitForSeconds(timeWait);
     }
     yield WaitForSeconds(animation[attackToUse + adding].length - timeWait * hitContainer.length - initialDelay);
     AfterAttackFunction();
 }

This function makes use of a custom class(Hit) to create the hitboxes. In turn, Hit accesses an array of a different class Hitbox.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ExplodingCookie · Jun 18, 2013 at 08:01 PM

I have solved it, For everyone with a similar problem, call your function with StartCoroutine(functionName) to make it eligible to be halted with StopCoroutine(functionName) and StopAllCoroutines.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with enemy AI 1 Answer

Creating basic enemy animation and attacking 4 Answers

Super Sonic Movement Help 1 Answer

How do I make my AI attack in the FPS tutorial? 0 Answers

Melee range AI 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges