-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Unity Cookbook
By :

For 3D games, the Rigidbody component has a useful method called AddExplosionForce(...)
that will cause an object to look as if it explodes from a given position. However, there is no such method for Rigidbody2D components. In this recipe, we’ll write an extension method for the Rigidbody2D
class so that we can add an explosionForce
method for 2D objects.
Thanks to Swamy for posting the code for the Rigidbody2D
extension class’s explosion force on Unity Forum (Nov. 21, 2013), which this recipe is based on:
Figure 8.60: Bugs being violently forced away from an invisible explosion point
This recipe builds on the previous one, so make a copy of that project and work on the copy for this recipe.
To create an explosionForce
method for 2D physics objects, follow these steps: