Page 1 of 1

Collision Types - colliding with one object but not another.

Posted: Mon Sep 08, 2014 9:50 pm
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 :)

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

Posted: Tue Sep 09, 2014 7:25 am
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.