Page 1 of 1

[Sorted]Passing through certain objects with Physics

Posted: Wed Feb 03, 2016 8:59 am
by rjoukecu
Hi guys,
I'm trying to solve a problem with collisions. I would like to pass throu certain objects (spikes(trap triggers), enemies, etc...), but thing is I have no clue how
to do that and wasn't able to find a solution.
The only thing I was able to come up with is this:

Code: Select all

function preSolve(a, b, coll)
	if a:getUserData() == "player" then
		if b:getUserData() == "spike" then
			coll:setEnable(false)
		end
	end
end
It's not giving me any errors but, on the other hand, it doesn't do anything :crazy:
And fo course I would like to know, If there is more elegant way, how to deal with "ghost" objects.
Thank you. :nyu:
PS: Traps are those levitating rectangles

Edit: I changed player and enemy object into square, but that got me a proper error : :roll: :crazy:

Re: Passing through certain objects with Physics

Posted: Wed Feb 03, 2016 1:11 pm
by Ranguna259
Maybe it's because a is not always the player and b is not always the spike. Try doing this:

Code: Select all

function preSolve(a, b, coll)
   if (a:getUserData() == "player" or b:getUserData() == 'player') then
      if (b:getUserData() == "spike" or a:getUserData() == 'spike') and a:getUserData() ~= b:getUserData() then --either a is player or spike and b is spike or player but b and a cannot be both player or spike at the same time
         coll:setEnable(false)
      end
   end
end

Re: Passing through certain objects with Physics

Posted: Wed Feb 03, 2016 6:57 pm
by rjoukecu
Sorted, afterfew more hours of diigin, I just added this line: objects.spikes.fixture:setSensor(true)
Phew

Re: [Sorted]Passing through certain objects with Physics

Posted: Thu Feb 04, 2016 8:22 am
by Ranguna259
That can be done too but keep in mind that spikes won't collide with anything now.