[Resolved] collision detection query

Hi,
I’ve just started playing with the physics engine and have hit a bit of a wall…
I have a number of animals (all stored in a table “animals”) that are dropping from the top of the screen. When they hit the floor they bounce like they should which is good, however I would like it so that if any of the animals are of a certain type (for example a hippo) then rather than bounce, I want them to explode (using particle candy).
What I’m stuck on is how to check if the animal that has hit the floor is a hippo and then return the x,y to be used for the particle emitter.

Hopefully that makes some sense.

Cheers
Chris
[import]uid: 7841 topic_id: 30367 reply_id: 330367[/import]

just assign a id to your animal.
when you create your animals do something like:

animal.id = “hippo”

then in your collision event handler do something like

if self.id == “hippo” then
– remove object and call particle candy
end [import]uid: 13632 topic_id: 30367 reply_id: 121634[/import]

Cheers Ojnab,
That does of course make perfect sense, but still stuck with a couple of bits…
a) How and where do I set up the collision event handler?
b) How do I detect if the collision is with the floor and not with another animal?

[import]uid: 7841 topic_id: 30367 reply_id: 121638[/import]

a)
read how to set up collision detection here:
http://developer.coronalabs.com/content/game-edition-collision-detection

b)
like this:
when creating the floor assign a id:
floor.id = “floor”

in the collision detection handler do this:
if self.id == “hippo” and event.other.id == “floor” then
– do stuff
end
[import]uid: 13632 topic_id: 30367 reply_id: 121643[/import]

Haha, thanks very much for that, I’d just managed to work it out myself exactly how you described it.
Many many thanks for your help :slight_smile:
[import]uid: 7841 topic_id: 30367 reply_id: 121650[/import]

Just a quick note, Corona For Newbies Part 4 covers this kind of thing. (In case you want a little additional info.)

Peach :slight_smile: [import]uid: 52491 topic_id: 30367 reply_id: 121800[/import]

just assign a id to your animal.
when you create your animals do something like:

animal.id = “hippo”

then in your collision event handler do something like

if self.id == “hippo” then
– remove object and call particle candy
end [import]uid: 13632 topic_id: 30367 reply_id: 121634[/import]

Cheers Ojnab,
That does of course make perfect sense, but still stuck with a couple of bits…
a) How and where do I set up the collision event handler?
b) How do I detect if the collision is with the floor and not with another animal?

[import]uid: 7841 topic_id: 30367 reply_id: 121638[/import]

a)
read how to set up collision detection here:
http://developer.coronalabs.com/content/game-edition-collision-detection

b)
like this:
when creating the floor assign a id:
floor.id = “floor”

in the collision detection handler do this:
if self.id == “hippo” and event.other.id == “floor” then
– do stuff
end
[import]uid: 13632 topic_id: 30367 reply_id: 121643[/import]

Haha, thanks very much for that, I’d just managed to work it out myself exactly how you described it.
Many many thanks for your help :slight_smile:
[import]uid: 7841 topic_id: 30367 reply_id: 121650[/import]

Just a quick note, Corona For Newbies Part 4 covers this kind of thing. (In case you want a little additional info.)

Peach :slight_smile: [import]uid: 52491 topic_id: 30367 reply_id: 121800[/import]