Only one Collision...

Hi
How to make only one collision when ball drop to the floor.
I can’t make ball.isActive = false. because a I have a lot of balls, I want them to make collisions one by one but only once… (balls are bouncing)

if event.phase ==began and event.other name == “ball” then …
Thanks for help… [import]uid: 13156 topic_id: 9716 reply_id: 309716[/import]

Do you mean you only want to HANDLE one collision? So you want the event handler to fire on the first collision (when the ball first hits the ground), but not the subsequent ones?

Try just adding a property to the object in the collision event handler:

[lua]if self.collidedWithGround then
return
else
self.collidedWithGround = true
– handle your collision here
end[/lua]

Just remember to set the object.collidedWithGround to nil again once you want to handle collisions with that object again. [import]uid: 49372 topic_id: 9716 reply_id: 35414[/import]

s2alexan hi

Thanks this exactly what I mean but I have to add collision to the ground or to the balls ? because right now my balls are event.other.name == “balls” all balls has a name “balls”. Collision I added to the ground.
Can you try to help me once more ?:slight_smile: [import]uid: 13156 topic_id: 9716 reply_id: 35427[/import]

local onTrashCollision = function(self, event)
if event.phase == “began” and event.other.name ==“balls” then

audio.play(popSound)

end
end [import]uid: 13156 topic_id: 9716 reply_id: 35428[/import]

It works fine either way, but I think it makes more sense to add the collision listener to the balls only, not the ground, then when the event handlers gets run, “self” will always be the ball that hit. [import]uid: 49372 topic_id: 9716 reply_id: 35434[/import]

Thanks s2alexan
Collision is added to balls
My solution :

local onTrashCollision = function(self, event)
if event.phase == “began” and self.name ==“ball” and event.other.name == “trashBottom” and self.isActive then

audio.play(popSound)
self.isActive = false
end
end

Works perfect. [import]uid: 13156 topic_id: 9716 reply_id: 35679[/import]