Collision

Here is my problem:
I have 3 Physics objects, Ball1, Ball2, and flag. I want to know only when Ball1 hits the flag, not Ball2. I also DONT want to know if Ball1 hits Ball2.

Basically I want to know when Ball1 and the flag have touched. Thanks ahead.

  • Chandler Mayo

[import]uid: 104852 topic_id: 21423 reply_id: 321423[/import]

Use filters to make ball2 not report collisions with ball1, you can include a filter for the flag and ball2 or in the flag and ball2 collisions just disregard it if one of the objects is ball2 [import]uid: 3826 topic_id: 21423 reply_id: 84852[/import]

That’s we’re I am having trouble. Any sample code? [import]uid: 104852 topic_id: 21423 reply_id: 84854[/import]

[code]
local physics = require ‘physics’

physics.start()
physics.setGravity( 0, 9.8 )

local circle1 = display.newCircle( 100,100, 5 ) ball2
circle1.myName = “circle1”
circle1.x = 50
local circle2 = display.newCircle(100,100,5) — ball1
circle2.myName = “circle2”

local rect = display.newRect( 0,0 , 100,10 ) – flag
rect.x = 200
rect.y = 450
rect.rotation = 90
rect.myName = “rect”

local rect2 = display.newRect( 0,0 , 300,10 )
rect2.y = 450
rect2.rotation = 20

rect2.myName = “rect2”

physics.addBody( circle1, “dynamic”, {friction=0, bounce=0, density=0 } )
physics.addBody( circle2, “dynamic”, {friction=0, bounce=0, density=0 } )

physics.addBody( rect, “kinematic”, {friction=1, bounce=.2, density=1 } )
physics.addBody( rect2, “static”, {friction=1, bounce=.2, density=1 } )

circle2:addEventListener(“collision”, circle2) — attach collision listener to the object ball1

function circle2:collision (event)

if event.other.myName == “rect” then

–do what ever you what to do
– rect:removeSelf()

end

–[[
you can add as many if statement as you want
if event.other.myName == “rect2” then

–do what ever you what to do
– rect:removeSelf()

end

–]]

end

Please read the physics documentation section.

Diginutscorp@gmail.com
twitter @diginutscorp

[import]uid: 40990 topic_id: 21423 reply_id: 84869[/import]

Hi,
Thanks your code works the way I want it to. The documentation has is set up differently.

-Chandler Mayo [import]uid: 104852 topic_id: 21423 reply_id: 84960[/import]