Collision detected only by name

Hi everyone.
i am using this function to detect collisions between objects, but i am having some problems, because this function dont work, can give me some help?

  
 local ball1 = display.newImage("")  
 ball1.x = math.round(\_W\*0.5); ball1.y = math.round(\_H\*0.2)  
 physics.addBody(ball1,"kinematic", { density=2, bounce=0.3,friction=2, radius=25});  
 local\_group:insert(ball1)  
  
 local block = display.newImage("block.png");  
 block.x = math.round(\_W\*0.25)  
 block.y = math.round(\_H\*0.98)  
 block.isVisible = true;  
 physics.addBody(block, "kinematic", { density=2,friction=2})  
 block:toFront();  
 block.myName ="object"  
 local\_group:insert(block)  
  
 function ball1:collision(event)  
 if event.other.name=="object" then  
 block:removeSelf()  
 return true  
 end  
 end  
 ball1:addEventListener("collision",ball1)  

Thanks [import]uid: 26056 topic_id: 20795 reply_id: 320795[/import]

the problem is your object name does not match to your collision function. What you want to do is there two ways to do it

[code] local block = display.newImage(“block.png”);
block.x = math.round(_W*0.25)
block.y = math.round(_H*0.98)
block.isVisible = true;
physics.addBody(block, “kinematic”, { density=2,friction=2})
block:toFront();
block.myName =“object”
local_group:insert(block)

function ball1:collision(event)
if event.other.myName==“object” then
block:removeSelf()
return true
end
end
ball1:addEventListener(“collision”,ball1) [/code]

or

[code]local block = display.newImage(“block.png”);
block.x = math.round(_W*0.25)
block.y = math.round(_H*0.98)
block.isVisible = true;
physics.addBody(block, “kinematic”, { density=2,friction=2})
block:toFront();
block.name =“object”
local_group:insert(block)

function ball1:collision(event)
if event.other.name==“object” then
block:removeSelf()
return true
end
end
ball1:addEventListener(“collision”,ball1) [/code]

Just pick only one! but they both work enjoy

Tell me if it worked

:slight_smile: [import]uid: 17058 topic_id: 20795 reply_id: 81763[/import]

wow, i didnt create two threads with the same problem :S
Yes sebitttas both works great, very complete and simple explication, thank you very much :slight_smile: [import]uid: 26056 topic_id: 20795 reply_id: 81834[/import]