Collision handling for overlaping fixtures

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
TRI99ER
Prole
Posts: 13
Joined: Fri May 28, 2021 3:28 pm

Collision handling for overlaping fixtures

Post by TRI99ER »

I need to implement behavior as follows:
There are two dynamic fixtures A and B and there is another static fixture G which acts as a ground. I want both fixture A and B to be affected by gravity and they need to be stopped by fixture G. Simple enough, I did it. The next thing is, both these fixtures A and B should be able to pass one through the other, but still generate lp callbacks. Basically they need to act as sensors to one another, but act as NOT sensors to everything else, including G fixture (so they don't fall through).

How can I manage to do this? I set A to category 2 and B to category 3. If I set the masks for these, they would be able to pass through one another, but don't generate lp callbacks. Without masks they generate lp callbacks, but can't pass through one another. If I make any of the bodies a sensor, two bodies would interact as I need, but sensor would fall through the ground.

Can anyone help me? I do not use any physics wrappers or libraries. If it can't be done with vanilla lp, than maybe you know a library that can do it.

If nothing works, than I would need to make an annoying workaround of duplicating the fixtures for both objects, make one of them affected by gravity and set a mask for the other object, and the second fixture to set as a sensor. This should work, but feels janky and unnecessary.

Thank you for any helpful replies.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Collision handling for overlaping fixtures

Post by pgimeno »

Maybe you can have one of the bodies with two fixtures using the same shape, one being a sensor and the other not?

Edit: oops, I didn't read the last paragraph, sorry. But you only need one of the bodies like this, not both. So, three fixtures in total: the sensor, and the two that can collide with the static one.
TRI99ER
Prole
Posts: 13
Joined: Fri May 28, 2021 3:28 pm

Re: Collision handling for overlaping fixtures

Post by TRI99ER »

Thank you for quick reply. Yeah, that sounds like it should work.

But your answer sounded, like this is not a frequent thing people do, although possible. For me it seems kind of essential to have overlapping events for objects. Is it not common to do this in Love 2D? Then what do people do instead? Maybe there's a more optimal classic solution.

The overall behavior I want is like this. Player controls a character and there is an object. Whenever character would be overlapping this object, player can perform an action that involves both. So that would also mean notifying player about the ability to perform an action and also with which specific object (because there could be many identical objects). Using beginContact callback seems like no-brainer for me.

I guess I can instead of doing it this way make a query whenever I need the action done and leave two fixtures with masks (character and object). That might seem like a good solution, but I would still want to make a visual update to let player know, that the action can be done between two specific object instances, so that would mean I would need to find good times to query for objects to update GUI. Every frame would work, but I feel like it's expensive... Unless it's not in Love2D.
I don't know of any opportune moment to make a query, obviously character would need to be in right state (like on the ground etc.), but that still leaves me with query every frame in that state.
The object would be instanced and may have multiple instances, so can't do anything with it, that doesn't involve running even more code per instance per frame.

Please let me know your thoughts on this, if possible and sorry for wasting time, if this doesn't make sense.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Collision handling for overlaping fixtures

Post by ivan »

Why do you need a callback between the two fixtures if you want them to act like sensors anyways? One way to do it is using https://love2d.org/wiki/Contact:setEnabled but it doesn't make sense. The proper way is to use collision filtering/masking to ignore the collision between the two dynamic fixtures.
TRI99ER
Prole
Posts: 13
Joined: Fri May 28, 2021 3:28 pm

Re: Collision handling for overlaping fixtures

Post by TRI99ER »

And if I want to have collision callbacks between two bodies and them only, while not blocking bodies from overlapping, then what? Why can I only set up filters to ignore category completely, but can't set filter to allow category to act as a sensor in the specific filter I choose.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 57 guests