Detecting what has had a collision

How do I work out when a collision is made by two specific objects. Example  BallA and BallB when they collide make a sound, but if they hit a wall they do not?

The function below does not work, it plays a sound no matter what they hit, walls and ceiling, I just want to play a sound when ballA and ballB collide? the print line is reporting the correct collisions.

local function myCollision(self, event)

   

    if { event.phase == “begin” } then 

   

              

       print (self.myName … ": hit " … event.other.myName) --this works

       if {self.myName == “ballA” and event.other.myName == BallB } then

          audio.play(clicksound)

        end 

        

elseif  { event.phase == “ended” } then 

                 

        print (self.myName … ": collection ended with "… event.other.myName)

          --audio.play(clicksound)

        --end

 end

  

end

thank you

Hi Sorry to bump, can anyone help?

Hi @andrew085,

For this, you should assign a custom property to each object, like “.objectType”, and set it to whatever is appropriate. Then, upon collision, check if the object is a ball and, if true, then play the sound (otherwise don’t).

Hope this helps,

Brent

Hi Sorry to bump, can anyone help?

Hi @andrew085,

For this, you should assign a custom property to each object, like “.objectType”, and set it to whatever is appropriate. Then, upon collision, check if the object is a ball and, if true, then play the sound (otherwise don’t).

Hope this helps,

Brent