- Home /
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)
After finding these items, the script should go through one by one checking if anything is blocking it (props or static objects)
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
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%
(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#
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);
}
}
}
}
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
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
}