# HitTestObject on a Box2D-object

**URL:** https://forum.kirupa.com/t/hittestobject-on-a-box2d-object/329173
**Category:** flash
**Created:** [July 28, 2012, 12:26pm UTC](https://forum.kirupa.com/t/hittestobject-on-a-box2d-object/329173 "2012-07-28T12:26:47Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Tompa](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@Tompa](https://forum.kirupa.com/u/Tompa)
#### Post date: [July 28, 2012, 12:26pm UTC](https://forum.kirupa.com/t/hittestobject-on-a-box2d-object/329173/1 "2012-07-28T12:26:47Z")

</div>

Hello!  
I’ve started playing around with Box2D and I’ve encountered a problem I can’t figure out.  
I got 4 walls and a point that’s floating around on the stage searching for collisions with the walls.  
Here is the code that’s creating the walls:

```auto
public function add_map():void {    
    var wallSize:int = 5;
    for (var k:uint = 0; k < 4; k++) {
        var my_body:b2BodyDef = new b2BodyDef();
        my_body.type = b2Body.b2_staticBody;
        var my_box:b2PolygonShape = new b2PolygonShape();
        switch(k) {
            case 0:
                [COLOR=#008000]// Top[/COLOR]
                my_body.position.Set((stage.stageWidth/2) / world_scale, (wallSize/2) / world_scale);
                my_box.SetAsBox((stage.stageWidth/2)/world_scale, wallSize/world_scale);
                break;
            case 1:
                [COLOR=#008000]// Right[/COLOR]
                my_body.position.Set((stage.stageWidth-wallSize) / world_scale, (wallSize/2) / world_scale);
                my_box.SetAsBox(wallSize/world_scale, (stage.stageHeight - (wallSize/2))/world_scale);
                break;
            case 2:
                [COLOR=#008000]// Bot[/COLOR]
                my_body.position.Set((stage.stageWidth/2) / world_scale, (stage.stageHeight-wallSize) / world_scale);
                my_box.SetAsBox((stage.stageWidth/2)/world_scale, wallSize/world_scale);
                break;
            case 3:
                [COLOR=#008000]// Left[/COLOR]
                my_body.position.Set((wallSize/2) / world_scale, (wallSize/2) / world_scale);
                my_box.SetAsBox(wallSize/world_scale, (stage.stageHeight - (wallSize/2))/world_scale);
            break;
        }
        var my_fixture:b2FixtureDef = new b2FixtureDef();
        my_fixture.shape = my_box;
        my_fixture.density = 100.0;
        my_fixture.friction = 10;
        var body:b2Body = world.CreateBody(my_body);
        body.CreateFixture(my_fixture);
        [COLOR=#b22222]mapParts.push(my_body);[/COLOR]
    }
}

```

And here’s the code I’m using to determine if there’s any collisions going on

```auto
var objects:Array = getObjectsUnderPoint(thePoint);    
for (var k:uint = 0; k < objects.length; k++) {
        for (var i:uint = 0; i < mapParts.length; i++) {
            if (objects[k] == [COLOR=#b22222]mapParts*[/COLOR]) {
                trace("Wall detected");
        }
    }
}

```

I think that the problem is that \*\*my\_body \*_from the **addMap()-function** isn’t the real object that’s visible on the stage_(so I can use getObjectUnderPoint to check if it’s colliding)  
(Marked with red color)  
\*  
\*Thanks in advance,  
Tompa

(Title was meant to be named ‘HitTestPoint on a Box2D-object’)\*
