Hello,
I am spawning a couple of 1x1m boxes from the top, when they reach ground and are not moving anymore, I check each block's collision and try to determine witch one are in contact with other block. To do this I iterate through all of the world's contacts and check the world manifold normal:
Basically I want to detect when a block is on the floor and has one block on each of his side touching it. The problem is that some block, even when they seems to meet all condition visually (I have put them all line up in a row and they can't move left or right when I apply a force on them), won't have those three collisions. They each seems to have the bottom collision (0,1), but most of them either don't have the left or right collision. I see a lot of them having the left or right collision twice though.
Is this normal? Or perhaps I'm just doing it wrong...
I am spawning a couple of 1x1m boxes from the top, when they reach ground and are not moving anymore, I check each block's collision and try to determine witch one are in contact with other block. To do this I iterate through all of the world's contacts and check the world manifold normal:
Code:
for(b2ContactEdge* e = b->GetContactList(); e; e=e->next)
{
b2WorldManifold worldManifold;
e->contact->GetWorldManifold(&worldManifold);
//bottom (0, 1)
if(worldManifold.normal.x > -0.05f && worldManifold.normal.x < 0.05f &&
worldManifold.normal.y > 0.95f && worldManifold.normal.y < 1.05f )
{
hasBottomContact = true;
}
//right (1, 0)
else if(worldManifold.normal.x > 0.95f && worldManifold.normal.x < 1.05f &&
worldManifold.normal.y > -0.05f && worldManifold.normal.y < 0.05f )
{
hasRightContact = true;
}
//left (-1, 0)
else if(worldManifold.normal.x > -1.05f && worldManifold.normal.x < -0.95f &&
worldManifold.normal.y > -0.05f && worldManifold.normal.y < 0.05f )
{
hasLeftContact = true;
}
}
{
b2WorldManifold worldManifold;
e->contact->GetWorldManifold(&worldManifold);
//bottom (0, 1)
if(worldManifold.normal.x > -0.05f && worldManifold.normal.x < 0.05f &&
worldManifold.normal.y > 0.95f && worldManifold.normal.y < 1.05f )
{
hasBottomContact = true;
}
//right (1, 0)
else if(worldManifold.normal.x > 0.95f && worldManifold.normal.x < 1.05f &&
worldManifold.normal.y > -0.05f && worldManifold.normal.y < 0.05f )
{
hasRightContact = true;
}
//left (-1, 0)
else if(worldManifold.normal.x > -1.05f && worldManifold.normal.x < -0.95f &&
worldManifold.normal.y > -0.05f && worldManifold.normal.y < 0.05f )
{
hasLeftContact = true;
}
}
Basically I want to detect when a block is on the floor and has one block on each of his side touching it. The problem is that some block, even when they seems to meet all condition visually (I have put them all line up in a row and they can't move left or right when I apply a force on them), won't have those three collisions. They each seems to have the bottom collision (0,1), but most of them either don't have the left or right collision. I see a lot of them having the left or right collision twice though.
Is this normal? Or perhaps I'm just doing it wrong...