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 /
This question was closed Jul 22, 2014 at 06:41 PM by NerdRageStudios for the following reason:

Other

avatar image
0
Question by NerdRageStudios · Jul 22, 2014 at 02:01 PM · physicscollideroverlapsphere

Random results with physics.OverlapSphere and AOE attacks

Hi, I am using the following code to create an area of affect magic spell.

It works fine, but seems to have some random results in hit detection. For example, I can see enemies within range, I trigger this and nothing happens, trigger it a second time and they all die.

Sometimes it triggers the first time, sometimes the third.

Can anyone look at this and find out why this seems to have seemingly random results?

             if (playerInventory.playerOneMagicPotions >= 1 && magicAttackInProgress == false)
             {
                 magicAttackInProgress = true;
                 speechPlayerScript.speech.Say("Using Spell", 3);
                 Instantiate(magicParticle, transform.position, transform.rotation);
                 Collider[] cols = Physics.OverlapSphere(transform.position, -20.0f);
                 foreach (Collider col in cols)
                 {
                     if (col.tag == "Enemy")
                     {
                         ScriptEnemyDamage e = col.gameObject.GetComponent<ScriptEnemyDamage>();
                         if (e != null)
                         {
                             e.TakeDamage(playerActualAttributes.playerOneActualMagicDamage);
                         }
                     }
                 }
                 yield return new WaitForSeconds(3.0f);
                 magicAttackInProgress = false;
             }

Any help would be greatly appreciated.

Comment
Add comment · Show 2
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 robertbu · Jul 22, 2014 at 02:14 PM 1
Share

Put some Debug.Log() statements in here to deter$$anonymous$$e:

  • Are you making it to line 5?

  • How many colliders are found in the OverlapSphere() call?

  • Is 'e' ever null?

  • Are you calling into the coroutine more often than 3.0 seconds (i.e. are you stacking up coroutines)?

  • Any chance that 'playerActualAttributes.playerOneActual$$anonymous$$agicDamage' could be 0.0?

avatar image NerdRageStudios · Jul 22, 2014 at 06:41 PM 0
Share

Thanks for the advice Roberbu, I feel a bit stupid now, as it was working perfectly and I couldn't find any errors in my code at all, until hours later it hit me that the enemy was healing itself.... sigh, I really should remember what I have coded into my own game lol :D

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

22 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Detect collider collision ,identify and access colliding colliders 0 Answers

Physics.OverlapSphere not detecting Instantiated Objects 1 Answer

Does OverlapSphere() return the colliders in any particular order? 1 Answer

overlapsphere to destroy NPCs on exit 1 Answer

Trying to use colliders on trees to interact with player 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