First Object collision not registering

Hey Guys,

Looking to see what could be the reason my first “Bug” isn’t registering a collision but all subsequent ones do as per the video below.

[media]https://db.tt/9XoirwP8[/media]

https://db.tt/9XoirwP8 - VIDEO OF THE ISSUE

here is my Collision code and my physics.addBody for the 2 objects.

[lua]function onCollision (event)
if (event.phase == “began”) then
print( “In Collision Function” )
end
if (event.object1.name == “screen” and event.object2.name == “enemyBug”) then
–Stop Tap Event Listener on the Bug
event.object2:removeEventListener(“tap” , bugKilled)

elseif (event.object1.name == “windowObj” and event.object2.name == “enemyBug” and powerup_windowObj.isVisible == true) then
if powerup_windowLives >= 1 then
event.object2.bodyType = “static”
event.object2:removeEventListener(“tap” , bugKilled)

–print( “in collision function” )

transition.cancel ( event.object2.trans )

local showbugsplatter = display.newSprite( sheetBugSplatter, sequenceData)
showbugsplatter.x = event.object2.x
showbugsplatter.y = event.object2.y
showbugsplatter:play()
display.remove( event.object2 )
event.object2 = nil

function removeshit( )
display.remove( showbugsplatter)
end
removebugandsplatter = timer.performWithDelay( 300, removeshit )
powerup_windowLives = powerup_windowLives - 1
bugsKilled = bugsKilled + 1

elseif powerup_windowLives < 1 then
powerup_windowObj.isVisible = false
event.object2.bodyType = “static”
event.object2:removeEventListener(“tap” , bugKilled)

transition.cancel ( event.object2.trans )

local showbugsplatter = display.newSprite( sheetBugSplatter, sequenceData)
showbugsplatter.x = event.object2.x
showbugsplatter.y = event.object2.y
showbugsplatter:play()
display.remove( event.object2 )
event.object2 = nil

function removeshit( )
display.remove( showbugsplatter)
end
removebugandsplatter = timer.performWithDelay( 300, removeshit )
powerup_windowLives = 10
bugsKilled = bugsKilled + 1
end
end
end[/lua]

[lua]

– setup window

powerup_windowObj = display.newImageRect( “powerup_windowObj.png”, 98, 180  )

powerup_windowObj.x = display.contentWidth * 0.50 

powerup_windowObj.y = display.contentHeight * 0.49 -1

powerup_windowObj.name = “windowObj”

physics.addBody( powerup_windowObj, “static”, { isSensor=true } )

group:insert(powerup_windowObj)

powerup_windowObj.isVisible = false

[/lua]

[lua]

physics.addBody( bug[TotalBugs], “dynamic”, { isSensor=true,radius=10} ) – need to change back to dynamic

–bug[TotalBugs].isBullet = true

bug[TotalBugs].name = “enemyBug”

group:insert(bug[TotalBugs])

[/lua]

Any help would be awesome. Thanks guys this has me stumped for the last few days.

Hey Guys,

It appears I may have fixed this. Not sure why this would have fixed it but I set the game gravity to [lua]physics.setGravity( 0, 0 )[/lua] and just set all the objects to Dynamic.

Not sure why without this the first collision didn’t fire but all others did when I never changed the body type of my objects. 

Will re-test once I get home and confirm.

I like the removeshit() function. :slight_smile:

I see no problem with the code but try not inserting your objects to any groups and see if it fixes the problem. I still get some weird collision issues between display objects in different display groups. All gets resolved if I don’t add them to a group… I know there is a logic behind it that all other developers avoid but I fail to grasp it as of yet.

Hey Guys,

It appears I may have fixed this. Not sure why this would have fixed it but I set the game gravity to [lua]physics.setGravity( 0, 0 )[/lua] and just set all the objects to Dynamic.

Not sure why without this the first collision didn’t fire but all others did when I never changed the body type of my objects. 

Will re-test once I get home and confirm.

I like the removeshit() function. :slight_smile:

I see no problem with the code but try not inserting your objects to any groups and see if it fixes the problem. I still get some weird collision issues between display objects in different display groups. All gets resolved if I don’t add them to a group… I know there is a logic behind it that all other developers avoid but I fail to grasp it as of yet.