Object Collision remove

Hello corona community,
i need some help here, i am trying to make a stars system, when my ball collide with star object she remove the star, but when she collides with one block she removes the block too and i only want to remove the star objects, not the block objects, how i can make it if my ball have this function:

function spawner:collision (event) event.other:removeSelf() end ball1:addEventListener("collision", spawner) [import]uid: 26056 topic_id: 15886 reply_id: 315886[/import]

Keep names for your stars.

[lua]starObject = display.newImage(“star.png”)
starObject.name = “star”[/lua]

Now filter out these stars in your listener.

[lua]function spawner:collision (event)
if event.other.name==“star”
return
end
event.other:removeSelf()
end
ball1:addEventListener(“collision”, spawner)[/lua]

Or you can use collision filters for your stars.
http://developer.anscamobile.com/forum/2010/10/25/collision-filters-helper-chart
But the first method is straight forward! [import]uid: 64174 topic_id: 15886 reply_id: 58739[/import]

oh thank you very much, it will resolve a lot of my problems :slight_smile: [import]uid: 26056 topic_id: 15886 reply_id: 58741[/import]

can i have physics for per exemple, my ball have physics.setGravity( 0,9.8 ) and my objects have physics.setGravity( 0,0 ), it is possible?
because i need to have gravity on the ball but dont want gravity on the objects, because if the objects are dynamic with gravity they are affected, but if they are kinematic or static, they arent affected by gravity but cant be removed by collision with the ball, how can i resolve it? [import]uid: 26056 topic_id: 15886 reply_id: 58742[/import]

For Corona to detect collisions, you need at least ONE of the colliding bodies to be dynamic. Since your ball object is dynamic,
you can keep your other objects as static or kinematic. Rest assured, collisions with the ball will be detected. :slight_smile: [import]uid: 64174 topic_id: 15886 reply_id: 58749[/import]

I think you can set gravity only for the whole “world”, but you can make some bodies weight zero - it’s famous as the weight watchers hack :wink: [import]uid: 70114 topic_id: 15886 reply_id: 58750[/import]

thanks for both :slight_smile: how can i make some bodies to weight zero? [import]uid: 26056 topic_id: 15886 reply_id: 58753[/import]

[lua]physics.addBody(object,“static”,{density=0})[/lua]
That should do! [import]uid: 64174 topic_id: 15886 reply_id: 58754[/import]

yeh i know it, but if it is dynamic and have gravity, is impossible to have the object stopped ? [import]uid: 26056 topic_id: 15886 reply_id: 58757[/import]

Satheesh, i tried the code that you give me, and it isnt work, something is wrong, if i use my function:

function ball1:collision (event)  
 event.other:removeSelf()  
 end  
 ball1:addEventListener("collision",ball1)  

the game run on the simulator, and make what i want, but without any filter, because i only want to remove thing with “star” name

and if i use your function, the game dont run :confused: try it to see plz, it will not run, but if you replace the function by the function above, will run

[code]
module(…, package.seeall)
function new()

local physics = require “physics”
physics.start()
physics.setDrawMode( “hybrid” )
physics.setGravity( 0,0 )

local ball1 = display.newCircle( 80, 120, 20 )
ball1:setFillColor( 0, 255, 0 )
physics.addBody(ball1,“static”)–{ density=2, bounce=0.3, radius=25});

ball1.x = 250; ball1.y = 100

local function touch(event)
if event.phase == “ended” then
physics.setGravity( 0,9.8 )
ball1.bodyType = “dynamic”

end

end
ball1:addEventListener( “touch”, touch )

block1 = display.newRect( 50, 50, 50, 50 )
block1.name = “star”
block1:setFillColor( 255, 255, 255, 100 )
physics.addBody(block1, “kinematic”)-- { density=2, friction=0, bounce=0 })
block1.x = 250 block1.y= 250
function ball1:collision (event)
if event.other.name==“star”
return
end
event.other:removeSelf()
end
end
ball1:addEventListener(“collision”,ball1)
end
[/code] [import]uid: 26056 topic_id: 15886 reply_id: 58783[/import]

oh, glad to see your question was answered [import]uid: 113909 topic_id: 15886 reply_id: 83882[/import]

Hi

i am starting learn corona for game development. someone please guide me how to remove both object on collide in corona.

Thanx
[import]uid: 233450 topic_id: 15886 reply_id: 144734[/import]

Hi

i am starting learn corona for game development. someone please guide me how to remove both object on collide in corona.

Thanx
[import]uid: 233450 topic_id: 15886 reply_id: 144734[/import]

Hi

i am starting learn corona for game development. someone please guide me how to remove both object on collide in corona.

Thanx
[import]uid: 233450 topic_id: 15886 reply_id: 144734[/import]

Hi

i am starting learn corona for game development. someone please guide me how to remove both object on collide in corona.

Thanx
[import]uid: 233450 topic_id: 15886 reply_id: 144734[/import]