So I’m trying to add an explosion to an object falling on the ground. I’m using Physics.OverlapSphere, but the problem is this adds explosion force to the ground as well, which then adds explosion force to everything on the ground. Is there a way to limit the explosion to just the falling object, and everything it hits, but not add it to the ground?
Here is the script I am using attached to the falling object, a.k.a. “Player.”
function 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 hit.rigidbody)
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0);
}
}