How do you temporarily disable collisions? - 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
Ovidios
Prole
Posts: 29
Joined: Thu Dec 04, 2014 12:00 pm
Location: Berlin, Germay

How do you temporarily disable collisions? - love.physics

Post by Ovidios »

I just want an object to act as though it wasn't there, not colliding with anything? How would I do that?

Thanks in advance!
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: How do you temporarily disable collisions? - love.physics

Post by Vimm »

Not quite sure what you mean. If you don't want one object to collide with another object just don't check for collisions.

If you mean you only want it to not collide when say, a button is being held down, you could set a Boolean variable like canCollide=true
Then you could set that to false when you hold the button and have collision be checked only if canCollide is true.

Without knowing exactly what you mean and/or seeing the love file, it's hard to help, at least hard for me to help but I'm pretty new lol
User avatar
Ovidios
Prole
Posts: 29
Joined: Thu Dec 04, 2014 12:00 pm
Location: Berlin, Germay

Re: How do you temporarily disable collisions? - love.physics

Post by Ovidios »

Vimm wrote:Not quite sure what you mean. If you don't want one object to collide with another object just don't check for collisions.

If you mean you only want it to not collide when say, a button is being held down, you could set a Boolean variable like canCollide=true
Then you could set that to false when you hold the button and have collision be checked only if canCollide is true.

Without knowing exactly what you mean and/or seeing the love file, it's hard to help, at least hard for me to help but I'm pretty new lol
I'm using the physics-module and don't know how I would go about disabling collisions (both check and callback) for one body/shape/fixture. Sorry for not making that clear enough.
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: How do you temporarily disable collisions? - love.physics

Post by Vimm »

Ovidios wrote:
Vimm wrote:Not quite sure what you mean. If you don't want one object to collide with another object just don't check for collisions.

If you mean you only want it to not collide when say, a button is being held down, you could set a Boolean variable like canCollide=true
Then you could set that to false when you hold the button and have collision be checked only if canCollide is true.

Without knowing exactly what you mean and/or seeing the love file, it's hard to help, at least hard for me to help but I'm pretty new lol
I'm using the physics-module and don't know how I would go about disabling collisions (both check and callback) for one body/shape/fixture. Sorry for not making that clear enough.
Ah I don't think I can help then, I tend to avoid the physics module for reasons like that. I generally check collisions just by using a collision function
User avatar
Tanner
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Re: How do you temporarily disable collisions? - love.physics

Post by Tanner »

The easiest way is to use 'Fixture:setFilterData' to set the collision filtering mask to 0. Assuming you haven't changed any of the category, mask or group data, that would look like this: 'fixture:setFilterData(1, 0, 0)' and then turning collisions back on would be like this: 'fixture:setFilterData(1, 65535, 0)'.

Love also provides 'Fixture:setMask' (https://love2d.org/wiki/Fixture:setMask) which is a nicer way of dealing with those masks if you aren't used to bitwise operations. In your case where you want to turning everything off, though, 'setFilterData' is probably more straightforward.

You can read more about this stuff in the Box2D manual. http://www.box2d.org/manual.html
User avatar
Ovidios
Prole
Posts: 29
Joined: Thu Dec 04, 2014 12:00 pm
Location: Berlin, Germay

Re: How do you temporarily disable collisions? - love.physics

Post by Ovidios »

Tanner wrote:The easiest way is to use 'Fixture:setFilterData' to set the collision filtering mask to 0. Assuming you haven't changed any of the category, mask or group data, that would look like this: 'fixture:setFilterData(1, 0, 0)' and then turning collisions back on would be like this: 'fixture:setFilterData(1, 65535, 0)'.

Love also provides 'Fixture:setMask' (https://love2d.org/wiki/Fixture:setMask) which is a nicer way of dealing with those masks if you aren't used to bitwise operations. In your case where you want to turning everything off, though, 'setFilterData' is probably more straightforward.

You can read more about this stuff in the Box2D manual. http://www.box2d.org/manual.html
Thanks! Got it to work using "Fixture:setMask" since I only had one moving object!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 47 guests