I am building a game where you blow up asteroids and I need a way to detect if you are colliding with an asteroid, The asteroids are in an array but when a collision event happens, the tag says nil, so I can’t tell what I am colliding with. Please help!
This is the function that creates the asteroid (Is ran every 1.5 seconds)
function newAsteroid(x,y)
** local x = x**
** local y = y**
** local width = 30**
** local height = 30**
** local obj = display.newImage(“rock.png”, x, y)**
** obj.width = 100**
** obj.height = 100**
** obj.objectType = “asteroid”**
** physics.addBody(obj, {friction = 0})**
** table.insert(asteroids, obj)**
end
And this is the collision function
function playerCollision(event)
** if(event.target.objectType == “asteroid”) then**
** display.remove(event.target)**
** table.remove(asteroids, 1)**
** end**
end
Thank You in Advance!!