So I have a function that spawns balls and I want whichever ball that hits the floor to remove itself. What I have happening is they all disappear. Is it possible to have only the ball that touches the floor to disappear. I currently have the floor as a collision listener and now that I think about it I’m thinking I should add the collision listener to the balls instead. Let me know what you think. [import]uid: 35535 topic_id: 9505 reply_id: 309505[/import]
The balls would certainly be simpler if you are new to this; although either is perfectly acceptable provided it works as intended 
Peach [import]uid: 52491 topic_id: 9505 reply_id: 34741[/import]
I disagree. Why have dozen/hundreds of collision listeners when one is enough? event.target is the ballon you want to remove. [import]uid: 51516 topic_id: 9505 reply_id: 34772[/import]
Either way would work fine, one way is not better than the other - unless there were in fact hundreds of listeners, but the limiting factor there would likely be hundreds of physics bodies.
There is more than one way to do almost anything in Lua and if it works as intended and does not create any performance issues then it’s as good as any other.
But yes, if for some reason you’ve got hundreds of balls in play then you may want to use the ground; if not, as I suspect is the case, go with what you prefer - there is not a right or wrong way to do this if it works as you want it to.
Peach
[import]uid: 52491 topic_id: 9505 reply_id: 34807[/import]
So I put the listener on the balls and that is working well. The only problem is that I want the collision function to work whenever the ball hits the floor. What’s happening is that if a ball collides with anything it calls the collision function. Is there a way to specify that I only want the function to be called if it’s a collision between the ball and the floor? And thanks again for your help
[import]uid: 35535 topic_id: 9505 reply_id: 35585[/import]
Gotcha!
In the first line of the function performed on collision add;
[lua]if event.other.name == “ground” then[/lua]
Then add this line after ground.x and ground.y;
[lua]ground.name = “ground”[/lua]
Make sense?
[import]uid: 52491 topic_id: 9505 reply_id: 35599[/import]
Oh thank you so much Peach! You were super clear and I really do appreciate you helping me.
[import]uid: 35535 topic_id: 9505 reply_id: 35632[/import]
No worries at all Nate 
When you understand how this works it would be very easy to move the listener to the floor if you wanted to, to simplify things - although as mentioned above as you’re new to this, provided everything works as you want it to, you can always leave it as is.
Peach
[import]uid: 52491 topic_id: 9505 reply_id: 35693[/import]