AOE attack, Grenades and Ragdolls

I thought I’d post this before heading off for the long weekend.

4 Likes

Nice addition! I loved the skeleton explosion animation. Did you design that yourself?

1 Like

Actually, the explosion is done using physics. I have a version of the skeleton model that has separate meshes for each piece that I instantiate when a skeleton enemy dies. Then I instantiate the explosion and it applies the explosion force to everything in the blast zone.

Here is the key bit of code:

    private void ApplyForceToObjects() {
        var cols = Physics.OverlapSphere(transform.position, explosionRadius);
        var rigidbodies = new List<Rigidbody>();
        foreach (var col in cols) {
            if (col.attachedRigidbody != null && !rigidbodies.Contains(col.attachedRigidbody)) {
                rigidbodies.Add(col.attachedRigidbody);
            }
        }
        foreach (var rb in rigidbodies) {
            rb.AddExplosionForce(explosionForce * explosionRadius, transform.position, explosionRadius, 1f, ForceMode.Impulse);
        }
    }