Get contacts between sensor and ground

Hi !

Working on a game, I actually get if a sensor (m_sensor) has contacts with other bodies, except one (m_body) with this :
Code:
for (b2ContactEdge* ce = m_sensor->GetContactList(); ce; ce = ce->next)
{

  b2Contact* c = ce->contact;
  if(c->GetFixtureA()->GetBody() != m_body && c->GetFixtureB()->GetBody() != m_body) onGround = true;

}


The problem is that it returns false when it has collisions with the ground…
I looked with the debug and no contact appeared when in the ground.

Is it possible that the ground is filtered by default ?

Thanks
The sensor is not attached to the ground body?
No, I don't think so…

I set it like that :
Code:
b2BodyDef bodyDef;
        bodyDef.type = b2_staticBody;
   bodyDef.position.Set(x/PIXELS_PER_UNIT, y/PIXELS_PER_UNIT);
   bodyDef.fixedRotation = true;
   m_body = m_world->CreateBody(&bodyDef);
   
   b2PolygonShape box;
   
   b2FixtureDef fixtureDef;
   fixtureDef.shape = &box;
   fixtureDef.density = 0.2f;
   fixtureDef.friction = 0.6f;

   box.SetAsBox(6.5f / PIXELS_PER_UNIT, 1.5f / PIXELS_PER_UNIT);
   fixtureDef.isSensor = true;
   m_sensor[0] = m_world->CreateBody(&bodyDef);
   m_sensor[0]->CreateFixture(&fixtureDef);
static-static, kinematic-static, and kinematic-kinematic bodies do not create contacts.
Ah ! Thanks !
But how can I do to avoid my sensor to fall then ? (I move it with transformation because I just need it to detect collisions)
A bit hacky, but you could just cancel gravity using ApplyForce. Are you moving the sensor in big steps? In that case you may be better off using b2World::QueryAABB and then use dmTestOverlap on each fixture of interest.
I'll try by "cancelling" the gravity.
Thanks ! 😀

EDIT : Well… I tried and it didn't work…
By vewing with the debug, I saw that my sensor become taller when I jump, instead of going up with the character body… (this, with our without the force).
This problem didn't happen when It was a staticBody.

What's wrong ?
Sheeft wrote:
What's wrong ?


No idea. Why is the geometry of your sensor changing?
I don't know… I'll test with statics bodies to check if the problem really come from there.

EDIT : Actually, with staticBody, shapes are goob but it remains the problem of contacts…
Also, my character can only go to the left and stuck on it (in fact two sidesensors must avoid such an effect but they just don't allow me to go right).

Well, If you want to know, here is my code for moving the character : http://pastie.org/948773

Maybe I'll use b2World::QuerryAABB then, but how do you use it, it isn't mentioned in the manual…
And well, what is dmTestOverlap ? there is no occurence in the source code.
Sheeft wrote:
Maybe I'll use b2World::QuerryAABB then, but how do you use it, it isn't mentioned in the manual…
And well, what is dmTestOverlap ? there is no occurence in the source code.


http://box2d.org/manual.html#_Toc258082976

There is a typo where it is called Query instead of QueryAABB.

I'm not sure why you need sensors. Why not look at the contact points on the character body?

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