I know how to check for collisions in the update loop – but I’m in a position where I need to see if two bodies are touching or overlapping in box2D. I have pointers to these objects and I don’t want to check while moving through update.
I am still learning Box2D so apologies if this is a dumb question. I have tried to solve this for an hour or so now but I’m not having any luck.
It looks like you can do this using b2TestOverlap or maybe b2CollideCircles (since the objects are b2CircleShapes). If either of these is the correct strategy can you get the shape from a given body, and what should I use as the transform values? If these aren’t the way to go, how can I check if two given b2Body objects are overlapping or touching.
UPDATE: Here’s the code that I got thanks to LearnCocos2D:
-(BOOL)isTouchingCentre:(b2Body*)bodyToTest{
//body is a b2Body object
bool overlap = b2TestOverlap(body->GetFixtureList()->GetShape(), bodyToTest->GetFixtureList()->GetShape(), body->GetTransform(), bodyToTest->GetTransform());
return overlap;
}
Not sure about the details of b2TestOverlap but I would give it a try. You can get the necessary info from the bodies, assuming they only have one shape: