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 djdrool91 · Jul 07, 2012 at 01:02 PM · c#cannonaoe

Area Effect Damage

Hey Everyone,

Alright so I have this kamikaze enemy that is holding a bomb and upon getting in range of the main character or it's health reaches 0, it will blow up and deal damage within an area to only certain objects if in range (Other enemies, Main player and destructible props).

I know that to get the collider's within an area I have to use Physics.OverlapSphere but upon Googling and reading up documentation, I still don't quite get how I can use and apply this function.

My process step-by-step: 1. When activated, the bomb will "Blow up" casting the overlap sphere looking for only certain objects with tags (Other enemies, Main player and destructible props)

  1. After finding these items, the script should go through one by one checking if anything is blocking it (props or static objects)

  2. If a static object is blocking the found object then nothing happens. However if an destructible object is in the way then only the nearest will get damaged

  3. After checking for the obstructed objects, the script should calculate the distance of the object from the centre of the blast and deal a percentage of the full damage. if directly in the middle then 100%

  4. (I'm not sure when to do this) The kamikaze enemy should then destroy itself but only after (or before please advise).

I found a few scripts that I'm trying to use for an AOE but no dice.

P.S I use C#

Comment
Add comment
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

3 Replies

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

Answer by whydoidoit · Jul 07, 2012 at 01:18 PM

I suggest you have a collider set to isTrigger = true that represents the area of effect of the kamikaze enemy. Then in a script attached to the enemy with the collider:

     public List<Transform> potentialTargets = new List<Transform>();

     void OnTriggerEnter(Collider other)
     {
         if(other.gameObject.tag == "whatever") {
             potentialTargets.Add(other.gameObject.transform);
         }
     }

     void OnTriggerExit(Collider other) 
     {
          potentialTargets.Remove(other.gameObject.transform);
     }

    public void InflictDamage()
    {
           foreach(var t in potentialTargets)
           {
                RaycastHit hit;
                if(Physics.Raycast(transform.position, (t.position - transform.position), 100, out hit)) 
                {
                        if(hit.transform == t) 
                        {
                               t.SendMessage("ApplyDamage", 10);
                        }
                }

 
           }
    }
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
avatar image
0

Answer by viralvector_games · Jul 07, 2012 at 03:46 PM

http://viralvector.weebly.com/products.html Explosives pack covers area effect and other type of are or explosion based effects

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

Answer by nventimiglia · Jul 07, 2012 at 05:59 PM

I use a coroutine for my splash damage script.

 IEnumerator Explode(){
  collider.enable = true;
  yield return 1;
  collider.enable = false;
 }
 
 OnTriggerEnter(Collider other){
  // send damage message to other
 }
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

8 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Renderer on object disabled after level reload 1 Answer

Initialising List array for use in a custom Editor 1 Answer

Illuminating a 3D object's edges OnMouseOver (script in c#)? 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