onCollision event

By default, all bodies collide with all other bodies, but i want to fine-tune this behavior. For example, i have 4 obects one of them are let’s say hero(Dynamic body), 2 enemy(static body) and one reward(dynamic) object

if enemy collides with reward the game ends

and even if enemy collide with hero the game ends

but i don’t want end the game when when hero collide with reward i want display as

local text “” you won "  something like this 

my current code is

function onCollision (event)
object:removeSelf()

 
 local text = display.newText(“Game Over. Try Again”, display.contentCenterX, display.contentCenterY, native.systemFontBold, 50)

Runtime:addEventListener(“collision”, onCollision)

Can anone help me .

Hi @adamrifau,

As a clarification, all bodies actually do not collide with all other bodies. Collisions will only register when one (or both) bodies are of type “dynamic” (the default). You will not receive collisions between, for example, a “static” and “kinematic” body, two “kinematic” bodies, or two “static” bodies.

In addition to this behavior, the best way to fine-tune collisions is to use collision filters. This process, and a useful worksheet to determine the values, is included in this guide:

http://docs.coronalabs.com/guide/physics/collisionDetection/index.html#filtering

Hope this helps,

Brent

thanks

Hi @adamrifau,

As a clarification, all bodies actually do not collide with all other bodies. Collisions will only register when one (or both) bodies are of type “dynamic” (the default). You will not receive collisions between, for example, a “static” and “kinematic” body, two “kinematic” bodies, or two “static” bodies.

In addition to this behavior, the best way to fine-tune collisions is to use collision filters. This process, and a useful worksheet to determine the values, is included in this guide:

http://docs.coronalabs.com/guide/physics/collisionDetection/index.html#filtering

Hope this helps,

Brent

thanks