A little help?

Well, looks like I have to resort back to the forums again. In my little game I’m having objects falling and a little guy catching. I have 8 objects total. 4 for + points and 4 for - points. For a start, I have the 1st object falling 10 times and adding to the score if caught. I’m kinda lost. First, I can’t get the object to disappear if it hits the ground and having the 3 other objects adding values to the score. Also the other 4 ‘bad’ objects adding - value. Along with having a continuous flow of the objects falling instead of a set number. I tried to create different functions and tables and just can’t get it right.

score = 0
frameCounter = 1
objectsDropped = 10

function onLocalCollision(self,event)
if(event.phase == “began”) then
if(self.id == “object1”) then
if(event.other.id == “player”) then
vx, vy = self:getLinearVelocity()

if(vy > 3) then
score = score + 1
scoreText.text = tostring(score)
self.isVisible = false
self:removeSelf()
end function/ifs

local object1 = display.newImage( “object1.png”, 180, -100)
object.rotation = 10
physics.addBody(object1, {density = 2.0, friction = 1.5,bounce=0.3})
object1.id = “object1”
object1.collision
object:addEventListener(“collision”, object1)

local function onFrame(event)
frameCounter = frameCounter + 1
objectsDropped = objectsDropped - 1
local object1 = display.newImage( “object1.png”)
object1.x = math.random(0, 310)
object1.y = 0
object1.rotation = math.random(0,360)
physics.addBody(object1, {density/friction/bounce})
object1.id = “object1”

object1.collision = onLocalCollision
object1.addEventListener(“collision”, object1)
end function/if

Runtime:addEventListener(“enterFrame”, onFrame) [import]uid: 114389 topic_id: 22264 reply_id: 322264[/import]

It looks like you’re only trying to remove an object that hits the player in that function; is that part working? [import]uid: 52491 topic_id: 22264 reply_id: 88808[/import]

Yeah that part is working. I actually have the object falling 10 times and disappearing when it hits the player. I just tried to get things going now nothing seems to work. [import]uid: 114389 topic_id: 22264 reply_id: 88823[/import]

That is because you have collision detection for the player but not the ground.

Try changing code to something like;

[lua]if(event.other.id == “player”) then
–Your code to remove object/add points here
elseif (event.other.id == “ground”) then
–Your code to remove object here[/lua]

Make sense? :slight_smile: [import]uid: 52491 topic_id: 22264 reply_id: 88837[/import]

YES! Haha, I was always putting a space between elseif before. Thank ya! For taking the time to answer such a question! [import]uid: 114389 topic_id: 22264 reply_id: 88909[/import]

Not a problem, happy to help :slight_smile: [import]uid: 52491 topic_id: 22264 reply_id: 88991[/import]