I am creating a game in which a player moves left and right to avoid obstacles. For some reason the collision event is triggered only when two of the same types of objects collide (a player and a player, an obstacle and an obstacle). I have tried many different things and nothing seems to work. Is there something wrong with the scope, if so how can I fix it? I am very confused, Thank You.
I have a player object:
function newPlayer( )
local self= display.newImage( “rocket.png”,screenWidth/2, screenHeight/1.25 )
local image_outline = graphics.newOutline( 2, “rocket.png” )
physics.addBody( self, “dynamic”,{
outline=image_outline , density=1.0, friction= 0.3, bounce= 0.02} )
self.isSleepingAllowed= false
–more code in player object but thats all that is needed for this question
end
An object function that creates a pair of rectangles and adds them to the overall obstacle group:
slalom= display.newGroup()
local leftWall= display.newRect( start-screenWidth/2, 0, screenWidth, 50 )
physics.addBody( leftWall, “static”, {density=10,friction=0.2,bounce=.01} )
local rightWall= display.newRect( leftWall.x+(screenWidth)+width, 0, screenWidth, 50 )
physics.addBody( rightWall, “static”, {density=10,friction=0.2,bounce=.01} )
slalom:insert( leftWall )
slalom:insert( rightWall )
self:insert(slalom)
I create a runtime listener to sense collision:
Runtime:addEventListener(“collision”, onCrash)