- Home /
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() ?
Answer by MrMetwurst2 · Sep 06, 2012 at 09:53 PM
I noticed it won't work without a collider attached.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Physics update rate problems 1 Answer
RigidBody Script Conflict 1 Answer
Question on Physic Materials, Rigibodies, and Acelleration 0 Answers
Force to Velocity scaling? 2 Answers