What's the best way to get the point of collision in box2d. I'm using it with cocos2d and Objective C, but I imagine the API is similar in other languages. Using the b2ContactListener class will produce b2Contact objects, but I can't find any information on the contact position.
Asked
Active
Viewed 1,156 times
2
-
looks like I killed the party – Aram Kocharyan Dec 16 '11 at 14:38
-
i think the [Demo](http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone) would work for you! – Marine Dec 23 '11 at 12:48
-
Thanks, I've gone through this a while back. I'm using b2Body's so detecting the collisions is still easy. – Aram Kocharyan Dec 24 '11 at 04:48
2 Answers
0
You can use the following code to get the point of collision
b2Body *bodyA = contact->GetFixtureA()->GetBody();
b2Body *bodyB = contact->GetFixtureB()->GetBody();
if ((bodyA->GetFixtureList()->GetFilterData().categoryBits == Categorybits1 || bodyA->GetFixtureList()->GetFilterData().categoryBits == categoryBits2) && (bodyB->GetFixtureList()->GetFilterData().categoryBits == categoryBits2 || bodyB->GetFixtureList()->GetFilterData().categoryBits == Categorybits1))
You can get body positions through this code.....
even i am searching how to get point of collision

Aram Kocharyan
- 20,165
- 11
- 81
- 96

Umesh Sharma
- 388
- 5
- 23
-
Cheers for that - I haven't really returned to this since 2011 though - hopefully it's useful to others. – Aram Kocharyan Dec 23 '13 at 10:45
0
try this method
OBJECT1_CATEGORY_BITS = 0x00000001;
OBJECT2_CATEGORY_BITS = 0x00000002;
void MyContactListener::PreSolve(b2Contact *contact, const b2Manifold
*oldManifold)
{
b2Fixture *fixtureA = contact->GetFixtureA();
b2Fixture *fixtureB = contact->GetFixtureB();
b2Filter filterA = fixtureA->GetFilterData();
b2Filter filterB = fixtureB->GetFilterData();
if ((filterB.categoryBits == OBJECT1_CATEGORY_BITS) && (filterA.categoryBits == OBJECT2_CATEGORY_BITS))
{
b2Vec2 normal = contact->GetManifold()->localNormal;
NSLog(@"pointX : %f",normal.x);
NSLog(@"pointY : %f",normal.y);
}
}

Liolik
- 791
- 6
- 12