hey guy,
i wanna make an explosive…
np, i did it…but there’s a matter…
i want after collider hit some thing make that thing destroy…
i dunno if also there is any thing to make a mesh object separate… like it destroyed by an explosive… or simply remove it…
so i have a Grenade and explosive attach to it and call after 3 sec for one shot…
and last thing is an other mess object gonna to destroy…
thank you
If the target objects all have colliders then there is a very easy way to determine which ones are affected by the explosion. You can use Physics.OverlapSphere to return an array of all colliders within a given radius of a point. You can then call Destroy on all the colliders’ gameObjects:-
var cols = Physics.OverlapSphere(expPosition, expRadius);
for (i = 0; i < cols.Length; i++) {
Destroy(cols[i].gameObject;
}
There isn’t any built-in way to simulate the explosion damage to the meshes. You can code this yourself, but be warned that this type of thing tends to be complicated.
Just a suggestion, but you can also put tags on non-destructable/killable objects and just add a simple if statement to check if it has the tag or not.
var cols = Physics.OverlapSphere(expPosition, expRadius);
for (i = 0; i < cols.Length; i++)
{
if(cols[i].transform.tag != "indestructable")
{
Destroy(cols[i].gameObject;
}
}
Though, it may be gameObject instead of transform though
i also like to deform them…like first explosion make some dis-sort on mesh object shape and after several of that…
for example unreal engine provide crate that you just need to fire at them, and they just get desort … not remove from scene…
BTW, tnx to you…
sry for late… i’m in middle of term exam
seem there’s no way in unity ? right?
It say there’s nothing such “range” as cols member…
What should i use to detect the distance?
private var creationTime=Time.time;
var LifeTime=3;
var DoDamageRange :int[] =new int[5];
var DoDamagePower :int[] =new int[5];
var explosionPrefab:Transform;
function Awake ()
{
creationTime=Time.time;
}
function Update()
{
if(Time.time>creationTime+LifeTime)
{
Destroy(gameObject);
Instantiate(explosionPrefab,transform.position,Quaternion.identity);
//destroy around obj
var cols = Physics.OverlapSphere(transform.position, DoDamageRange[0]);
for (i = 0; i < cols.Length; i++)
{
if (cols[i].gameObject.tag=="turret")
{
GameObject.Find("GUI Text").guiText.text=""+ cols[i].gameObject.GetComponent("turretHealthController").TURRET_HEALTH;
if (cols[i].range < DoDamageRange[0])
{
cols[i].gameObject.GetComponent("turretHealthController").TURRET_HEALTH -= DoDamagePower[0];//Destroy(cols[i].gameObject);
}
else
{
if (cols[i].range < DoDamageRange[1])
{
cols[i].gameObject.GetComponent("turretHealthController").TURRET_HEALTH -= DoDamagePower[1];//Destroy(cols[i].gameObject);
}
else
{
if (cols[i].range < DoDamageRange[2])
{
cols[i].gameObject.GetComponent("turretHealthController").TURRET_HEALTH -= DoDamagePower[2];//Destroy(cols[i].gameObject);
}
else
{
if (cols[i].range < DoDamageRange[3])
{
cols[i].gameObject.GetComponent("turretHealthController").TURRET_HEALTH -= DoDamagePower[3];//Destroy(cols[i].gameObject);
}
else
{
if (cols[i].range < DoDamageRange[4])
{
cols[i].gameObject.GetComponent("turretHealthController").TURRET_HEALTH -= DoDamagePower[4];//Destroy(cols[i].gameObject);
}
else
{
//No Damage
}
}
}
}
}
}
}
}
}
Are you sure you need to check the range directly? (It seems as though the OverlapSphere call already does this.) If you do, you can use Vector3.Distance:-
range = Vector3.Distance(transform.position, cols[i].transform.position);