Hi guys, I have just started learning Corona and came across a problem that I have no how to solve. I’m trying to get a round object to collide with a square object and then trigger an event
-- Create Fox local function createFox() fox = display.newSprite(foxImageSheet, foxSequenceData) physics.addBody(fox, "dynamic",{density = 0.0, friction = 0.0, bounce = 0.0, radius = 17}) fox.x = display.contentWidth / 2 fox.y = -20 fox.myName = "fox" fox:setSequence("flying") fox:play() backgroundLayer:insert(fox) print("Fox created") end -- Create Bomb function spawnBomb() enemyCount = enemyCount + 1 -- enemies:toFront() enemyArray[enemyCount] = display.newSprite(obstaclesImageSheet, obstaclesSequenceData) enemyArray[enemyCount]:setReferencePoint(display.BottomCenterReferencePoint); enemyArray[enemyCount].x = math.random(40, display.contentWidth - 50) enemyArray[enemyCount].y = 580 enemyArray[enemyCount].speed = 3 enemyArray[enemyCount].myName = "bomb" physics.addBody(enemyArray[enemyCount], "static", {bounce = 0.0, radius = 11}) enemies:insert(enemyArray[enemyCount]) end function spawnSpike() enemyCount = enemyCount + 1 squareShape = { -50,-10, 50,-10, 50,10, -50,10 } -- enemies:toFront() enemyArray[enemyCount] = display.newSprite(obstaclesImageSheet, obstaclesSequenceData) enemyArray[enemyCount]:setReferencePoint(display.BottomCenterReferencePoint); enemyArray[enemyCount].x = math.random(60, display.contentWidth - 50) enemyArray[enemyCount].y = 580 enemyArray[enemyCount].speed = 1 enemyArray[enemyCount].myName = "spike" physics.addBody(enemyArray[enemyCount], "static", {shape=squareShape}) enemies:insert(enemyArray[enemyCount]) end function onCollision(event) if(event.object1.myName == "fox" and event.object2.myName == "bomb") then print("Bomb Collided!") -- triggers elseif(event.object1.myName == "fox" and event.object2.myName == "spike") then print("Spiked") -- doesn't trigger end end
The collision itself works fine, as in the round fox object will stay on top on the spike object. However the “Spiked” word isn’t printed when both collide.
If I change the spike object physics body to radius (instead of shape), the word “Spiked” will trigger.
Any help is very much appreciated. Thanks in advance.