Search Unity

AddExplosionForce2D Equivalent?

Discussion in '2D' started by Derf321, Dec 18, 2014.

  1. Derf321

    Derf321

    Joined:
    May 3, 2014
    Posts:
    3
    Hello!
    I'm pretty new to Unity, but I have a game in the works that's actually looking pretty good. Right now I have it so when the player collides with a block of ice, the ice shatters into pieces and the pieces fall off the map. The pieces are just the ice image manually chopped up and instantiated when the ice is hit. I'd like to make it so when the player collides with the ice, an explosion-like force is applied, pushing the ice pieces away from the point of impact.

    What would be the best way to do this? In 3D it looks easy to use AddExplosionForce, but I can't seem to find an easy way to push the pieces besides in a single direction (which would look odd). Application of torque (rotation) on the pieces would be nice too, like AddExplosionForce does for 3D, but it's not necessary. Is there a hidden command to do this that I can't find?

    Thanks for helping! These forums have already taught me an incredible amount =)
     
  2. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    AddForceAtPosition might suit your purposes. For each shard of ice, run AddForceAtPosition, where position is the epicenter of the explosion.
     
  3. Derf321

    Derf321

    Joined:
    May 3, 2014
    Posts:
    3
    Ah, thank you. I saw that command but I thought it was for something else. I wish there was a more efficient way of doing this, it seems silly to make a force for each object you want to act on, when there's already a 3D counterpart. Cheers!