- Home /
addExplosionForce radius and force have no effect
public float theForce;
public float theRadius;
...
theGameObject.AddComponent<Rigidbody>().AddExplosionForce(theForce, transform.position, theRadius);
return theGameObject;
...
theForce and theRadius are public floats. No matter what I adjust them to the explosion is too powerful. I tried using negative values to see if it would implode, still the same high velocity explosion. I've even tried very small numbers such as .0000000000001, and no difference. Anyone know if there is some bug here or am I doing something wrong?
I just tried adding mass of .00001 all the way to 10 and in between, didn't seem to have an effect.
theGameObject.GetComponent<Rigidbody> ().mass = 10f;
Answer by W.Walter · Apr 06, 2015 at 05:37 AM
You are applying the explosion at the objects center, which will make it have extreme/unpredictable responses. Move the explosion force to a better position. Your are doing the equivalent of an atomic bomb inside your game object, not beside it. Hope this helps :)
sound theory, will try and report back
edit: Strange, no matter where I move the force, same reaction. I'm stumped.
Rigidbody.AddExplosion force is designed to be used to add forces to surrounding objects (with linear falloff based on radius and force), after say a bomb explodes. If you're trying to add force to the rigidbody, (to explode it upwards or something) then you should use Rigidbody.AddForce. You can also tell it to use an 'explosion type' force. Rigidbody.AddForce will apply a force to the rigidbody in a specified direction, rather than calculating it based on the center of the explosion (as in Rigid.'AddExplosionForce'). Hope this explains things a bit :)
Okay, I removed the addExplosionForce, and just added the rigidbody, and I am still getting an 'explosion', possibly from intersecting? Very strange, but the problem must reside deeper in the code. Thanks for the info WW!Giving you the answer since you helped me narrow down the possibilities!
Answer by PsychoDuckArcade · Apr 06, 2015 at 10:07 PM
I've successfully used explosion force recently in a similar way. Yeah one problem I see that's already been mentioned is the explosion position; it won't have proper results in the center.
I also used explosionforce from a component on the gameObject being exploded, it worked fine.
I noticed however that the amount of force needs to be fairly high relative to the mass. For objects 1-10 in mass, I had to use force in the thousands (1000-10,000 should launch the object quite a bit).
Another thing to consider is the object's scale. Since force causes acceleration which is distance over time, a very large object covers a lot of distance so movement won't be as noticable without adjusting speed/forces accordingly. My objects with the settings I mentioned above (1-10 mass, 1000-10,000 explosion force) are sized 1-5 unity units. Remember 1 unity unit resembles 1 meter for the physics engine (anything to do with velocity, which is meters/unity units per second).
Lastly drag and friction are important factors as well, as they slow down movement, decrease accelerations, and increase decelerations.