1

I'm writing a game where a circle shape lands on a b2LoopShape consisting of a few hundred vertices.

I'm trying to determine whether my landing is smooth or not (landing along the edge or perpendicular to the edge) by using a contact listener but can't get it right.

Any ideas?

erik
  • 448
  • 5
  • 10

1 Answers1

0

A loop shaped is made up of multiple edge segments. You will need to loop over all the edge segments and find the closest point on each edge to your circle's center. The closest of all these should be the point actually used for the collision. If it is at one of the 'tips' of the edge segment it belongs to, the circle hit the end of the edge. If it is somewhere along the middle of the edge, it landed smoothly.

I may be misunderstanding what you mean by 'smoothly', but in any case if you do the above you will have the two endpoints of the edge that was actually hit, and the direction of travel of the circle, so you can use these to decide for yourself whether it's smooth or not.

iforce2d
  • 8,194
  • 3
  • 29
  • 40
  • Thank you! I have the first part figured out, but I'd like to come up with a clever method for the second part. – erik Jun 18 '11 at 22:52
  • I can't give you an actual answer because I have never done this before and know very little about it, but it seems to me that what you need is a ray cast (or two or three) and possibly a linear (or angular) velocity check. Good luck. – Aaron Goselin Jun 20 '11 at 10:14