# Box2D PhysExplosion

**URL:** <https://forum.kirupa.com/t/box2d-physexplosion/288964>\
**Category:** programming\
**Created:** [May 24, 2009, 5:15am UTC](https://forum.kirupa.com/t/box2d-physexplosion/288964 "2009-05-24T05:15:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![crucifix](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@crucifix](https://forum.kirupa.com/u/crucifix)\
**Post date:** [May 24, 2009, 5:15am UTC](https://forum.kirupa.com/t/box2d-physexplosion/288964/1 "2009-05-24T05:15:14Z")

</div>

Ive been trying to port a physexplosion function from C to AS3 and im getting a bit stuck and i was hoping that someone could help me out ![](http://forum.kirupa.com/uploads/kirupa/4187/77fb0e195ffd970c.gif) .

Here is my code so far,

```auto

private function PhysExplosion(locationPnt, Radius, Force)
      {
            var Sector:b2AABB;
            Sector.lowerBound.Set(locationPnt.x-Radius, locationPnt.y-Radius);
            Sector.upperBound.Set(locationPnt.x+Radius, locationPnt.y+Radius);
         var k_bufferSize:Number = 10;
         var buffer:Array = new Array(k_bufferSize);
            var count:int = m_world.Query(Sector, buffer, k_bufferSize);
            for (var i:int = 0; i < count; i++)
            {
               var Body:b2Body = buffer*.GetBody();
               var BodyPos:b2Vec2 = Body.GetWorldCenter();
//ERROR1------------------------------------------------------------------------------------
                        var HitVector:b2Vec2 = (BodyPos.x - locationPnt.x,BodyPos.y - locationPnt.y);
//-------------------------------------------------------------------------------------------
               var Distance = HitVector.Normalize(); //Makes a 1 unit length vector from HitVector
               if ((Body.IsDynamic())&&(Distance<=Radius))
               {
                  var HitForce = (Radius-Distance) * Force; //TODO: This is linear, but that's not realistic.
//ERROR2-----------------------------------------------------------------------------------
                                Body.ApplyImpulse(HitForce * HitVector, Body.GetWorldCenter());
//------------------------------------------------------------------------------------------
              };
            }

      };

```

My errors seem to be with declaring the hitVector and applying it. Any help would be greatly apreciated ![](http://forum.kirupa.com/uploads/kirupa/4990/9159c015948af455.gif)
