Collision and display groups problem

I make first Corona game and have some problem with detecting collisions.
I have mainGroup with ship (main.lua) and enemy module (enemy.lua)
In enemy module I have enemyGroup with enemyShip and laser inserted into enemyGroup… Enemy module returns enemyGroup (with enemyShip and laser)
In main.lua I insert enemy module to mainGroup. Adding collision, but ship colliding ONLY with enemyShip.

Here is full code main.lua :[code]
display.setStatusBar( display.HiddenStatusBar ) --Hide status bar from the beginning

_W, _H = display.contentWidth, display.contentHeight

local timeLastEnemy = 0;
mainGroup = display.newGroup();

local physics = require(“physics”)
physics.start(true);
physics.setDrawMode( “normal” ) – hybrid
physics.setGravity( 0, 0.5 )

local function onCollision(self, event)
–print('Self: '…self.name … ’ Other: ’ … event.other.name)
if event.phase == “began” then
– Ship + alienShip
if self.name == “ship” and event.other.name == “alienShip” then
–print(“Ship + alienShip”)
event.other.isVisible = false
end
if self.name == “alienLaser” and event.other.name == “ship” then
print(“Ship + alienLaser”)
self.isVisible = false
end
end
end

local ship = display.newImageRect( “hero.png”, 42, 47 );
ship:setReferencePoint( display.TopLeftReferencePoint );
ship.x = (_W * 0.5) - ship.contentWidth/2;
ship.y = 265;
ship.name = “ship”
ship.collision = onCollision
ship:addEventListener(“collision”, ship)
physics.addBody(ship, “kinematic”, {bounce = 0.8, density = 1})

mainGroup:insert(ship)

local spawnEnemy = function(event)
if event.time - timeLastEnemy >= math.random(2000, 3000) then
local alienShip = require(“enemy”).new()
alienShip:setReferencePoint( display.TopLeftReferencePoint );
alienShip.x = math.random(31, _W - 31);
alienShip.y = -alienShip.contentHeight
alienShip.name = “alienShip”
alienShip.collision = onCollision
alienShip:addEventListener(“collision”, alienShip)
physics.addBody(alienShip, “dynamic”, {bounce = 0})
–mainGroup:insert(alienShip)
timeLastEnemy = event.time
end
end
Runtime:addEventListener(“enterFrame”, spawnEnemy)
[/code]

enemy.lua full code:[code]
module(…, package.seeall)

function new(params)
local enemyGroup = display.newGroup();
local enemyShip = display.newImageRect( “enemy.png”, 34, 49 );
enemyShip:setReferencePoint( display.TopLeftReferencePoint );
enemyGroup:insert(enemyShip)
local laser = display.newImageRect( “enemy_fire.png”, 38, 21 );
laser:setReferencePoint( display.TopLeftReferencePoint );
laser.x = alienShip.x
laser.name = “alienLaser”
laser.collision = onCollision
laser:addEventListener(“collision”, laser)
enemyGroup:insert(laser)
physics.addBody(laser, “dynamic”, {bounce = 0})
laser.isSensor = true
return enemyGroup
end
[/code]

[import]uid: 75366 topic_id: 16064 reply_id: 316064[/import]

Simple way to understand game logic:

  1. mainGroup insert ship
  2. enemyGroup insert ship & insert laser
  3. mainGroup insert enemyGroup
    No collision “ship + laser”
    [import]uid: 75366 topic_id: 16064 reply_id: 59717[/import]