[Sorted]Passing through certain objects with 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
rjoukecu
Prole
Posts: 3
Joined: Wed Feb 03, 2016 7:51 am

[Sorted]Passing through certain objects with Physics

Post 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:
Attachments
Utter Darkness2.love
(30.57 KiB) Downloaded 108 times
Utter Darkness.love
(30.52 KiB) Downloaded 105 times
Last edited by rjoukecu on Wed Feb 03, 2016 7:02 pm, edited 1 time in total.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Passing through certain objects with Physics

Post 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
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
rjoukecu
Prole
Posts: 3
Joined: Wed Feb 03, 2016 7:51 am

Re: Passing through certain objects with Physics

Post by rjoukecu »

Sorted, afterfew more hours of diigin, I just added this line: objects.spikes.fixture:setSensor(true)
Phew
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: [Sorted]Passing through certain objects with Physics

Post by Ranguna259 »

That can be done too but keep in mind that spikes won't collide with anything now.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

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