Collision works for dynmaic bodies but not for floor bodies

hi,

I create dynamic bodies on fly and floor bodies at the beginning of the application. Why doese the collision detection works well for the dynamic bodies, but not for the floor bodies?? Is there a gerneral problem, or am I just to stupid?!

regards
That depends, could you post some code excerpts of your body creation?
for sure... in the following you see the creation of standard floor shapes.

in pStaticActors are all floorshapes be placed.
in another pDynamicActors are all dynamicshapes be placed.

for example rectangle:
Code:
private function createStaticRectangle(tData:Object):void
      {
         var tStaticShape:Sprite = new Sprite();
           tStaticShape.graphics.lineStyle(3, 0xff0000);
           tStaticShape.graphics.drawRect(tData.initX,tData.initY, tData.width, tData.height);
           
           var tStatic:b2PolygonDef = new b2PolygonDef();
         tStatic.SetAsBox((tStaticShape.width/2)/pPhysScale, (tStaticShape.height/2)/pPhysScale);
         tStatic.friction = 0.5;
         tStatic.density = 0.0;
         tStatic.restitution = 0.1;
         
         var tStaticDef:b2BodyDef = new b2BodyDef();
         tStaticDef.position.Set(tData.posX/pPhysScale, tData.posY/pPhysScale);
         
         pObject = {shape:tStaticShape, type:tStatic, bodyDef:tStaticDef};
addStaticShapes(pObject);
      }

Code:
private function addStaticShapes(tData:Object):void
        {   
           var tStaticBody:b2Body;
           tStaticBody = pWorld.CreateBody(tData.bodyDef);
         tStaticBody.CreateShape(tData.type);
         tStaticBody.SetMassFromShapes();
         
         pStaticActor = new StaticActor(tStaticBody, tData.shape);
         tStaticBody.m_userData = pStaticActor;
         pStaticActors.push(pStaticActor);
            drawArea.addChild(tData.shape);
        }   
That looks fine.

You could make your code a bit more descriptive, (call your sprite variables "sprite", and your shapedefs/bodydefs "shapeDef" and "bodyDef".. that would make it a bit easier for others to read, although I am sure that you understand this perfectly)

But, I cant discover anything wrong with that code. What are the symptoms? What do you mean by "collision detection doesn't work for floor bodies" ?
I have a program, where I have floorshapes (are generated at the beginning) and dynamicshapes (which are generated on fly). When I draw a new dynamicshape on fly, I create always really short a test body to have a look, if there is enough space or collides it with another body ... . That collision detection of the "checkcollisionbody" works just for the dynamicbodies. That means that he my checkcollisionbody recognise the dynamic but not the floor bodies. And I have no idea why.
Another thing is, that when I click on the floorshape (with GetBodyAtMouse) the programm finds also just the dynamic and not the floor bodies.

regards
When you run a normal simulation. Do the normal (dynamic) bodies collide with the floor?

Further more, is this "checkcollisionbody" a static body (mass=0)? Because static bodies never collide with eachother.
the dynamicshapes collide very well with the floor.

thats the code of the checkcollision bodies and I think they shouldnt be static

Code:
private function checkRectangle(tData:Object):void
        {
           var tWidth:Number = tData.widthRect;
           var tHeight:Number = tData.heightRect;
           var tX:Number = tData.xCoord;
           var tY:Number = tData.yCoord;
           
            var tRect:b2PolygonDef = new b2PolygonDef();
         tRect.SetAsBox((tWidth/2) / pPhysScale, (tHeight/2) / pPhysScale);
         tRect.friction = 0;
         tRect.density = 0;
         tRect.restitution = 0;
         tRect.isSensor = true;
         var tTestBodyDef:b2BodyDef = new b2BodyDef();
         tTestBodyDef.position.Set((tX + (tWidth/2)) / pPhysScale, (tY + (tHeight/2))/ pPhysScale);
         
         tObject = {shapeName:"rectangle", shape:tRect, bodDef:tTestBodyDef};
addcheckCollisionShapes(tObject);
        }


Code:
private function addcheckCollisionShapes(tData:Object):void
        {
           var tTestBody:b2Body;
           tTestBody = pWorld.CreateBody(tData.bodDef);
           tTestBody.CreateShape(tData.shape);
           tTestBody.m_mass = 1;
           pCheckActor = new CheckActor(tTestBody);
            pCheckActors.push(pCheckActor);   
        }
As a matter of fact, they are static.

You are creating them (world.CreateBody & body.CreatShape) when they still have a density of 0. Bodies with a density of 0 will automatically be made static. So, try giving them a higher density to begin with, that way they won't be initialized as static bodies, and they will be able to collide with static ones.
oh man... I have done a lot of things to get it running, but this solution was not on my plan!!


it works jippiiieee
But I still have one problem... the concave dynamic bodies!! I have one body, which is filled with a lot of polygonshapes (triangles)!! It seems to be a similar problem with them. They simulate very well, but dont recognise collisions with object which are drawing on fly.

Has anyone an idea why it doesnt work with bodies like that??

Original thread: https://box2d.org/forum/viewtopic.php?t=3052