0

So, I have a scenario in a Box2D project where a sensor "eye" (basically a line) collides with one or more objects, and I want to find the one that's closest to the bottom of the eye. This means that for each fixture colliding with the eye, I'd like to find the point(s) of collision, so that I can choose the closest point.

Right now, my code is structured to store a list of eyes and the things that collide with them in my contact listener's BeginContact, and to remove the appropriate stuff in EndContact. I'm planning to loop through this list once a timestep.

My question:

How would one best find points of collision outside of a contact listener? From what I can tell, the b2Contacts provided in BeginContact and EndContact don't persist, so I can't use the contact manifold they provide. Is looping through the eye's contact list my best bet?

Thanks!

Using Kripken's box2djs.

mostsquares
  • 834
  • 8
  • 27
  • looked [here](http://stackoverflow.com/questions/5033498/getting-contact-points-on-bodies-in-cocos2d-box2d?rq=1), but that question finds points in `BeginContact` – mostsquares Jun 10 '16 at 16:45
  • It sounds like you're describing the perfect use of a raycast in box2d. A ray is just a straight line that basically tells you what is in certain parts of the world. Have you looked into using that instead, or is that not what you're after? – Peter R Jun 14 '16 at 11:48
  • Oh wow... that's much cleaner. Thanks! – mostsquares Jun 14 '16 at 18:10

0 Answers0