0

I am new to Box2D and is currently trying to detect if an object (Ball) has managed to pass through another object (Goal) by using b2Contact. For this, I have implemented b2ContactListener and everything is working fine.

However, I was wondering, is there any way for me to set to detect collision for one direction only? For example, only from left to right, collision will not count if the ball passes through from right to left. I want to implement something like this from here as could be seen from the documentation.

In the documentation, they have detected the direction of the collision by using the points from the object as such

int numPoints = contact->GetManifold()->pointCount;
b2WorldManifold worldManifold;
contact->GetWorldManifold( &worldManifold );

However, for my case, I am using a b2CircleShape for my ball object, which indirectly returns the numPoints to be 0. Thus, I am unable to detect the collision using the above method. Is there any way I could detect the points from the circle? Or is there any way I could detect the direction of the collision?

1
  • Maybe you could take into account the relative velocity of the objects, and their positions?
    – Aiden Deom
    Jan 4, 2016 at 16:22

1 Answer 1

0

Maybe this will help you.

b2WorldManifold manifold;
contact->GetWorldManifold(&manifold);
manifold.normal.Normalize();
if(manifold.normal.x > 0){
   [...]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.