Page 1 of 1

How to get the contact collision side/normal in love.physics?

Posted: Tue Jan 10, 2017 4:59 pm
by cdArf
How do I get a contact's collision side (with a rectangle) in love.physics? I can't find anything in the documentation, but it should be possible, right?

Re: How to get the contact collision side/normal in love.physics?

Posted: Tue Jan 10, 2017 5:18 pm
by raidho36
I've never used Box2D but if I had to guess:

Every body generates Contact objects when they collide with anything, which you can query with body:getContacts() function. Each contact has a normal, which you can then query with contact:getNormal() function.

Re: How to get the contact collision side/normal in love.physics?

Posted: Tue Jan 10, 2017 5:51 pm
by scissors61
I think you have to create two shapes and fixtures for the same body and then add to each fixture a different userdata info. You could also create two raycasters for each side too.

Re: How to get the contact collision side/normal in love.physics?

Posted: Wed Jan 11, 2017 5:06 pm
by cdArf
Thank you raidho36! I can't believe I didn't notice that in the documentation, that's surprisingly simple. Thanks again!

Re: How to get the contact collision side/normal in love.physics?

Posted: Wed Jan 11, 2017 6:28 pm
by ivan
body:getContacts is good for "resting" contact, usually when one fixture is standing on top of the other.
A lot of collisions are resolved instantly, so you have to use the PostSolve callback to catch those.
Also, note that the collision normal is not the "collision side" but the axis along which the (non-penetration) impulses were applied.
Tangent/friction impulses are perpendicular to the normal.