Collision Types - colliding with one object but not another.

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
Snackrilege
Prole
Posts: 19
Joined: Sat Sep 06, 2014 8:50 pm

Collision Types - colliding with one object but not another.

Post by Snackrilege »

[SOLVED}

This is actually trivially easy. There are two parts.

fixture:setCategory() - sets the collision types
fixture:setMask() - sets the collision types that get ignored

thats all there is to it, really


------------------------------------------------------------------------
------------------------------------------------------------------------




While this thread is active, I'm going to try to figure this out on my own. Once i figure it out, I'll update this post. I just haven't seen any tutorials that deal with this.

It would be nice to have a chain that the player can walk through but still collides with the evironment (doesn't clip through walls, etc) or a sword that collides with other objects, but can be layered over top of the player's sprite, etc/

The functionality is implied by the existence of such things as body:getType/body:setType and fixture:setCategory, but I'm not sure if there is a "right" way to do this that is established within the community, or a library, or what have you.

thanks for any insight you can give me!

Once I get this sorted out, it will become searchable in the forums for anyone else with the same question, so no one need ask again :)
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Collision Types - colliding with one object but not anot

Post by Plu »

What you'll probably want to do is use this:
https://love2d.org/wiki/Body:setUserData

This allows you to assign a lua value (use a table!) to the object, which you can then use in your collision function to determine which collisions should work. It's best to make the main collision function only check types of objects and then call dedicated resolver functions.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests