Can you help with Collision Callbacks

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
ixjackinthebox
Prole
Posts: 45
Joined: Sun Apr 29, 2012 6:00 pm

Can you help with Collision Callbacks

Post by ixjackinthebox »

I have started looking at the CollisionCallbacks tutorial and in it it said on the page
A list of functions you can use on contacts can be found at the Contact page.

and on the contacts page there is Contact:isTouching and i wonder how to use it?

Also how can I find out what fixtures collided with each other?

and if I put this

Code: Select all

function beginContact(fixture_a, fixture_b, coll)
	collA = fixture_a:getUserData()
	collB = fixture_b:getUserData()
end
and then I did

Code: Select all

function love.update(dt)
	if collA == Objects.Player.fixture
		--do stuff
	end
Would that tell me if collA was the same as Objects.Player.fixture

Thanks in advance
User avatar
ixjackinthebox
Prole
Posts: 45
Joined: Sun Apr 29, 2012 6:00 pm

Re: Can you help with Collision Callbacks

Post by ixjackinthebox »

Anyone???
benhumphreys
Prole
Posts: 31
Joined: Thu Sep 13, 2012 2:10 am

Re: Can you help with Collision Callbacks

Post by benhumphreys »

Please re-read the physics tutorials on the Wiki.

In your code, please note that getUserData() will return you a custom string that you should have set somewhere.

So it will not equal the fixture object.

Here is something I use in my own code:

Code: Select all

-- In setup:
    pillar = {}
        pillar.b = lp.newBody(world, 600,400, "static")
        pillar.s = lp.newRectangleShape(200,200)
        pillar.f = lp.newFixture(pillar.b, pillar.s)
        pillar.f:setRestitution(0.0)
        pillar.f:setFriction(0.8)
        pillar.f:setUserData("some pillar")

-- Then later:
function beginContact(a, b, coll)
  if a:getUserData() == "some pillar" then
    -- do something
  end
end
Hopefully this will help.
Post Reply

Who is online

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