I have an object with a 1x1x1 BoxCollider and a Rigidbody with a mass of 1. It also has a child object with a SphereCollider of radius 50 and IsTrigger set to true. For some reason, when I call Rigidbody.AddExplosionForce() on this object, it gets blasted away as if by an insanely powerful force, even when the explosion force is neither very strong nor very close by. The larger I make the child SphereCollider’s radius, the greater the effect. Curiously, I do not see this effect when I use Rigidbody.AddForce(). I reported my findings in this SO post, thinking them to be a bug in the physics engine, but the comments there led me to believe that everything was behaving as expected. So here’s my question: how can I use Rigidbody.AddExplosionForce() on a GameObject with a large trigger somewhere in its hierarchy, without that trigger effecting it’s physics?
EDIT: Here is my test explosion script, copied from the linked SO post:
using UnityEngine;
public class Exploder : MonoBehaviour {
// HIDDEN FIELDS
private float _highY = 0f;
private bool _moving;
// INSPECTOR FIELDS
public Rigidbody Target;
public float ExplosionForce;
public float ExplosionRadius;
public float UpwardsModifier;
// EVENT HANDLERS
private void Update() {
// Explode on click
bool clicked = Input.GetMouseButton(0);
if (clicked) {
if (Target != null)
Target.AddExplosionForce(ExplosionForce, transform.position, ExplosionRadius, UpwardsModifier, ForceMode.Impulse);
}
// Report the object's highest y-level
if (Target.velocity.sqrMagnitude > 0) {
_highY = Mathf.Max(_highY, Target.transform.position.y);
_moving = true;
}
else if (_moving) {
Debug.LogFormat("Highest Y: {0}", _highY);
_highY = 0f;
_moving = false;
}
}
}