The problem I’m having is that the coins will randomly “glitch” around when contacting the thing I need to dodge.
I have 3 coins, one “player” and an object that randomly appears on the y axis and floats across the screen at various speeds. If I hit the random object, I die, but I want to be able to hit and collect the coins.
this is my code for one coin and the collision with movement function.
local yellowCoin = display.newCircle(_W*1.4, 0, 10)
yellowCoin:setFillColor(250,250,10)
physics.addBody(yellowCoin, “static”,{isSensor = true})
yellowCoin.myName = “coin1”
localGroup:insert(yellowCoin)
function yellowCoinsMove (event)
yellowCoin.x, yellowCoin.y = 0, math.random(50, 300)
yellowTran = transition.from(yellowCoin, {time=3000, x =_W*1.4, onComplete= yellowCoinsMove})
end
function yellowCoins (event)
if ( event.phase == “began” ) then
if event.object1.myName == “player” and event.object2.myName == “coin1” then
score.setScore (score.getScore()+10)
end
elseif ( event.phase == “ended” ) then
if event.object1.myName == “player” and event.object2.myName == “coin1” then
yellowCoinsMove()
end
end
end
yellowCoin:addEventListener(“collision”, yellowCoins)
[import]uid: 136878 topic_id: 24366 reply_id: 324366[/import]
[import]uid: 52491 topic_id: 24366 reply_id: 98434[/import]