Anyone else having an issue where the crate pieces just aren’t flying apart? My Unit ragdolls work just fine and it’s the same script applied to both pieces. I’ve verified that my gravity settings are set at default. I thought it may have been something I did when I set up the crate, but I downloaded the prefab from the lecture commit and am getting the same behavior.
The Destroyed Crate spawns correctly, but none of the pieces fly out with much force. I’ve even upped the explosionForce value in the script with no discernable difference.
public void Damage() {
Transform crateDestroyedTransform = Instantiate(crateDestroyedPrefab, transform.position, transform.rotation);
Vector3 randomDir = new Vector3(Random.Range(-1f,1f), 0, Random.Range(-1f,1f));
ApplyExplosionToChildren(crateDestroyedPrefab, 3000f, transform.position + randomDir, 10f);
Destroy(gameObject);
OnAnyDestroyed?.Invoke(this, EventArgs.Empty);
}
private void ApplyExplosionToChildren(Transform root, float explosionForce, Vector3 explosionPosition, float explosionRange) {
foreach (Transform child in root) {
if(child.TryGetComponent<Rigidbody>(out Rigidbody childRigidbody)) {
childRigidbody.AddExplosionForce(explosionForce,explosionPosition,explosionRange);
Debug.Log("AddedForce!");
}
ApplyExplosionToChildren(child, explosionForce, explosionPosition, explosionRange);
}
}