Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get local contact point for both bodies? #232

Closed
AndrewRayCode opened this issue May 12, 2016 · 1 comment
Closed

Get local contact point for both bodies? #232

AndrewRayCode opened this issue May 12, 2016 · 1 comment

Comments

@AndrewRayCode
Copy link
Contributor

I'm analyzing contacts in my scene by looping over world.narrowphase.contactEquations for player contacts. The problem is I don't know if the contact will be in bodyA or bodyB, and depending on which it is, I might the get local contact point (in contactPointA as documented here) from the "wrong" body. To calculate the normal for the "right" body, I have to do some translation math for every contact. Is there a better way to always get the local contact point for either body? I can assign an event listener to my specific player body, but I'm wondering if there's a nice way to do it with just reading a generic contact event and not knowing where it came from?

@schteppe
Copy link
Owner

I guess you always will have to check whether it's bodyA or B, and react differently depending on the result. Maybe you could make it nicer by implementing a handleContact method on each body instance, see the example here: http://www.iforce2d.net/b2dtut/collision-callbacks

When you know which one of the bodies you are interested in you may need to flip the normal. You can do this by just reversing the vector... Alternatively there could be a method on the event object for doing this. If you go for the handleContact method, pass in the reversed vector to it. Or the vector + a multiplier which is -1 or 1.

Other than this I'm out of ideas. I checked the box2d docs but its API don't help with this part either. If you have any suggestions on how to improve the API I'm all ears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants