Rigidbody.AddExplosionForce Is Not Working

I copy and pasted the unity API on
Rigidbody.AddExplosionForce
and it didn’t work, is their anything i have to do to my scene to prep it?

using UnityEngine;
using System.Collections;

// Applies an explosion force to all nearby rigidbodies
public class TestExplosion : MonoBehaviour {
    public float radius = 5.0F;
    public float power = 10.0F;
   
    void Start() {
        Debug.Log ("bang");
        Vector3 explosionPos = transform.position;
        Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
        foreach (Collider hit in colliders) {
            Rigidbody rb = hit.GetComponent<Rigidbody>();
           
            if (rb != null)
                rb.AddExplosionForce(power, explosionPos, radius, 3.0F);
           
        }
    }
}

Confirm your objects actually have a Rigidbody component on them. Change Power to 300.

OK, that the problem, i was using numbers that were way to small to do anything. after changing the power to 300 it moved the block. thank you.

I wanted to get the explosion after a collision and it doesn’t work, what do I have to do?
(I also tried changing power to 300 but keeps not working)

public class RomperVidrio : MonoBehaviour
{
    public Transform brokenObject;
    public float magnitudeCol, radius, power;

    void OnCollisionEnter(Collision collision)
    {
        if (collision.relativeVelocity.magnitude > magnitudeCol)
        {
            Destroy(gameObject);
            Instantiate(brokenObject, transform.position, transform.rotation);
            brokenObject.localScale = transform.localScale;
            Vector3 explosionPos = transform.position;
            Collider[] colliders = Physics.OverlapSphere (explosionPos, radius);

            foreach (Collider hit in colliders){
                Rigidbody rb = hit.GetComponent<Rigidbody>();
                if (rb != null)
                    rb.AddExplosionForce(power, explosionPos, radius, 3.0f);
     

            }
             

        }
    }
}

Did you already try LaneFox’s suggestions posted here 4 years ago? Because an explosive force of 3 is probably going to result in a similar force to a firecracker going off under a bus.

2 Likes

Yep mate, I tried, but it doesn’t want to do the thing

Not working for mee too…any updates??

1 Like

Use Bigger Numbers! I needed 1000 Power and 100 Upward Force…
Make sure your Rigidbody is NOT Kinematic

1 Like

I have a similar problem, I am trying to launch my player, but it doesn’t get knocked back at all, he has a Rigidbody, capsule collider, and player controller, the knock back number is 1500. it is not kinemetric either