x


AddExplosionForce() does not appear to have any effect

I'm having hard time with AddExplosionForce() as far as I can tell it has no effect or a negligent effect on the rigidbody.

My scenario is of a top-down 2.5D game, so all rigidbodies have their position Y constrained. In my particular scenario an object explodes and I'm spawning fragments, then I want the fragments to be pushed by the explosion of the original object that blew up.

So my code really is quite simple, a previous piece of code randomly created a few fragments around the object and the relevant piece of code is:

foreach (var fragment in fragments)
    fragment.rigidbody.AddExplosionForce(BlastForce, transform.position, BlastRadius, 0, ForceMode.Impulse)

If I replace the above code with the following:

foreach (var fragment in fragments)
{
    var posToFragmentVector = (fragment.transform.position - transform.position);
    var distance = posToFragmentVector.magnitude;
    var dir      = posToFragmentVector.normalized;
    if (distance < BlastRadius)
        fragment.rigidbody.AddForce(dir * BlastForce * (1 - (distance / BlastRadius)), ForceMode.Impulse);
}

Essentially doing what AddExplosionForce() advertises, minus the torque, then things work as expected.

I should note that the trigger for this piece of code is from an Update() and not a FixedUpdate(), but since I'm using a single call with ForceMode.Impulse and since ApplyForce() works I don't think that's the problem.

Am I doing something glaringly stupid, or is there something wrong with AddExplosionForce() ?

more ▼

asked Dec 29 '11 at 05:01 PM

amirabiri gravatar image

amirabiri
1k 16 26 36

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I noticed it won't work without a collider attached.

more ▼

answered Sep 06 '12 at 09:53 PM

MrMetwurst2 gravatar image

MrMetwurst2
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5093
x1880
x1797
x161

asked: Dec 29 '11 at 05:01 PM

Seen: 825 times

Last Updated: Sep 06 '12 at 09:53 PM