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

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

so you can find the point where collision happened.


Or you can use the rocket’s position itself