Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 jmparavicini · Feb 01, 2016 at 07:29 AM · explosionoverlapsphererocketaoe

Rocket Explosion not applying damage when hitting ground

Hi Guys,

So in my game there is a rocket launcher which fires rockets of course and when the rocket hits an enemy it does AoE damage, but my problem is that when the rocket hits the ground, the explosion function gets called but there is no AoE damage.

here is my rocket script:

 sing UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class rocket : MonoBehaviour {
 
     public float m_Speed;
     public float m_BlastRadius;
     private Rigidbody rb;
     public float m_BlastDamage;
     public GameObject m_Player;
     private Manager.Teams m_Team;
 
     public List<GameObject> m_PlayerChilds;
 
     void Start () 
     {
         rb = GetComponent<Rigidbody>();
         m_Team = m_Player.GetComponent<CurrentTeam>().Team;
         foreach (Transform child in m_Player.transform)
         {
             m_PlayerChilds.Add(child.gameObject);
         }
     }
 
     void Update () 
     {
 
     }
 
     void OnCollisionEnter(Collision col)
     {
         if (m_PlayerChilds.Contains(col.gameObject))
             Physics.IgnoreCollision(col.gameObject.GetComponent<Collider>(), GetComponent<Collider>());
 
         if (col.gameObject.GetComponent<CurrentTeam>() != null && col.gameObject.GetComponent<CurrentTeam>().Team == m_Team)
         {
             Physics.IgnoreCollision(col.gameObject.GetComponent<Collider>(), GetComponent<Collider>());
         }
 
         else
         {
             ExplosionDamage(col.transform.position, m_BlastRadius);
             Destroy(gameObject);
         }    
     }
 
     void ExplosionDamage(Vector3 center, float radius) 
     {
         Collider[] hitColliders = Physics.OverlapSphere(center, radius);
 
         foreach (Collider hitCollider in hitColliders)
         {
             if (hitCollider.GetComponent<CurrentTeam>() != null && hitCollider.GetComponent<CurrentTeam>().Team != m_Team)
             {
                 float distanceToEnemy = (center - hitCollider.transform.position).magnitude;
                 float m_Distance01;
                 m_Distance01 = Mathf.Abs(1 - (1 / radius * distanceToEnemy));
 
                 hitCollider.GetComponent<Stats>().ApplyDamage(0, m_Distance01 * m_BlastDamage);
             }
         }
     }
 
     void FixedUpdate()
     {
         rb.velocity = transform.forward * m_Speed;
     }
 }

so as I said the ExplosionDamage() gets called when the rocket hits the ground but no enemies take damage.

Thanks in advance for you help

-skullbeats1

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

1 Reply

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

Answer by graciasluigi · Feb 01, 2016 at 10:40 AM

Maybe is because you are performing the overlap sphere at the position of the colliding object... Where is the pivot of your ground?

You can try Collision.contacts[] http://docs.unity3d.com/ScriptReference/Collision-contacts.html so you can find the point where collision happened.


Or you can use the rocket's position itself

Comment
Add comment · Show 1 · 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 jmparavicini · Feb 02, 2016 at 03:41 AM 0
Share

thank you so much. I knew something was totally wrong with the script because it only sometimes applied the damage but i changed the position to the rocket position and now everything works like a charm. Again thank very much :D

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

34 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 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

Rocket Launcher explosion 1 Answer

AddExplosionForce won't have any effect. 1 Answer

Area of Effect damage trigger 2 Answers

OnCollisionEnter problem (RocketJump script) 1 Answer

Cast Source Instantiating Error 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