Hi
In my project I have collisions working well. I am now attempting to shot a missile from one moving object to another but the collision detection does not appear to be working. Here is my code, hopefully obvious?
function myCollision(self, event) if event.phase == "began" then print(event.target.type) print(event.other.type) -- print (event.target.type .. ": hit " .. event.other.type) elseif (event.phase == "ended") then end end bird = display.newSprite(sheet3, { name="b1", start=1, count=8, time=1000} ) bird.x = 130 bird.y = centerY/3 --random(\_H2) -500 --\* .5 bird.type = "bird" bird.xScale = .3 bird.yScale = .3 bird:play() group:insert( bird ) physics.addBody( bird ,"dynamic", { density=1.0, friction=1, bounce=0, radius=20}) bird.isFixedRotation=true --bird.isSensor = true function fireNut(event) local score = 0 images3 ={ "images/nut1.png", "images/nut2.png", "images/nut3.png", "images/nut4.png", "images/nut5.png", "images/nut6.png" } local randomImage2 = images3[math.random(1,6)] nutShot = display.newImage(group,randomImage2,10) nutShot.x= bird.x+60 + score nutShot.y = bird.y+10 nutShot.xScale = .1 nutShot.yScale = .1 physics.addBody( nutShot , "kinematic",{density=0, friction=0, bounce=0, radius=30}) nutShot.type = "badNut" nutShot.collision = myCollision nutShot:addEventListener("collision", nutShot) nutShot.isSensor = true nutShot.isBullet = true transition.to(nutShot, { time = 1000 + score, x = \_W + 100, y=cenerY}) -- transition = easingx.easeOutElastic }) score = score +150 end end end function jump(event) if (event.phase == "began") then fireTimer = timer.performWithDelay( 200, fireNut, 0) if gameOver ~= true then bird:applyForce(0,-800,bird.x, bird.y) end elseif (event.phase == "ended") then if fireTimer ~= nil then timer.cancel( fireTimer ) end end end sky:addEventListener( "touch", jump )