- Home /
Question by
thecoolracer · Nov 10, 2012 at 02:26 PM ·
rigidbodyexplosionexplode
How do I chack that my explosion hit another explosive and blows up the other explosive?
The question is simple, but the answer probably is not that simple. All my explosives are tagged with Explosive FYI. My script currently only blows away rigidbodies, but it doesn't blow up any more explosives in the explosion radius, only pushes them back Here is my script, its Javascript:
var Health : float = 100;
var ExplosionParticle : Transform;
var radius = 5.0;
var power = 10.0;
function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.tag == "AK47Bullet") {
Health = Health - 20;
}
}
function Update () {
if(Health <= 0) {
Explode ();
}
}
function Explode () {
var explosionPos : Vector3 = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
for (var hit : Collider in colliders) {
if (!hit)
continue;
if (hit.rigidbody)
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0, ForceMode.Impulse);
}
Instantiate(ExplosionParticle, transform.position, Quaternion(90,0,0,0));
Destroy(gameObject);
}
Comment