Objects should collide only with one category

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
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Objects should collide only with one category

Post by pauls313 »

I'm making a 2D soccer game, and the players are made of 2 objects: Head and feet.

I managed to, using groups, stop the feet and head from colliding with each other. But after adding a second player, I realized that the feet should actually ONLY collide with the ball and nothing else. How can this be achieved?
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Objects should collide only with one category

Post by ivan »

You don't need separate bodies, you can set the category and mask PER fixture. Also, you can solve this without using "groups". You need at least 3 categories "head", "feet" and "ball", correspondingly: 0x1, 0x2 and 0x4. The trick would be setting the collision masks correctly. The masks should be: 0x0, 0x4, 0x2 when the ball is on the ground in short the "head" category is ignored altogether. Set the first mask to 0x1 if you want the player "heads" to collide with each other.
Not sure if it's a good idea to use collision masks in this way, but it's hard to say without seeing the rest of the code.
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Re: Objects should collide only with one category

Post by pauls313 »

ivan wrote: Mon Nov 04, 2019 4:38 pm You don't need separate bodies, you can set the category and mask PER fixture. Also, you can solve this without using "groups". You need at least 3 categories "head", "feet" and "ball", correspondingly: 0x1, 0x2 and 0x4. The trick would be setting the collision masks correctly. The masks should be: 0x0, 0x4, 0x2 when the ball is on the ground in short the "head" category is ignored altogether. Set the first mask to 0x1 if you want the player "heads" to collide with each other.
Not sure if it's a good idea to use collision masks in this way, but it's hard to say without seeing the rest of the code.
I'm not really familiar with collisions mask, how would I do that?
Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 44 guests