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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
cdArf
Prole
Posts: 6
Joined: Sun Dec 25, 2016 12:28 am

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

Post 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?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

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

Post 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.
User avatar
scissors61
Citizen
Posts: 76
Joined: Fri Jan 08, 2016 10:16 am

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

Post 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.
User avatar
cdArf
Prole
Posts: 6
Joined: Sun Dec 25, 2016 12:28 am

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

Post by cdArf »

Thank you raidho36! I can't believe I didn't notice that in the documentation, that's surprisingly simple. Thanks again!
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 75 guests