- Home /
How can use AddExplosionForce to explode scattered objects?
I have a central cube named "Explosion" sitting on a plane with 4 cubes placed around it. I apply the following script to Explosion:
var radius = 100.0; var power = 1000.0; function Start () { Debug.Log("start"); // Applies an explosion force to all nearby rigidbodies var explosionPos : Vector3 = transform.position; var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
for (var hit : Collider in colliders) {
if (!hit)
continue;
if(hit.name=="Explosion")
continue;
if(hit.name=="Plane")
continue;
if (hit.rigidbody)
Debug.Log(hit.name);
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 10.0);
}
}
When I run this, the four cubes barely move at all. I increase the power value, but it has no affect. When I put the cubes at the same location as the Explosion cube, they appropriately explode, but I want to be able to have them placed randomly.
Answer by davedev · Feb 21, 2011 at 08:37 PM
Nevermind. I was editing default values in the script instead of the editor so I wasn't seeing any changes. Changes the editor variable values makes for some nice explosions.
Your answer
Follow this Question
Related Questions
AddExplosionForce 0 Answers
Default Unity Rigidbody.AddExplosionForce script problem 1 Answer
AddExplosionForce only goes up 0 Answers