Object falling - Loop.

I have tried to make a loop of an falling object but I didn’t succed. I tried many wait but I couldn’t find the right way to do it.  

What I want is when the object gets under the screen, to go back on top and fall again, creating a loop. 

This is how my object looks like :
 

local bara = display.newImage(“bara.png”)

bara.x = 175

bara.y = -math.random(500,1000)

physics.addBody( bara, “dynamic”, {bounce=0, density=5, friction=0})

bara.isFixedRotation = true 

bara.gravityScale = 1

Hi @raresrap,

There are various ways to handle this. You could either create an invisible “floor” (physics sensor object) that is somewhere off the bottom of the screen, then detect collision with it and send the falling object back to the top. Or, you could track the position of the falling object in a Runtime listener function and, when it gets below a certain y position, send it back to the top.

Hope this helps,

Brent

I’ve made a floor but in I think I’m not doing the collision right.

 

–floor

local podea = display.newImage(“floor.png”)

podea.x=0

podea.y=1100

physics.addBody(podea, “static”)

local function onCollision(event)

if event.phase == “began” then 

if event.object1.name == “bara”

then transition.moveTo( bara, { x=140, y=150 } )

end

end

end

Runtime:addEventListener(“collision”, onCollision)

Hi.  Is this for a class?  I ask because I just answered (or gave starter code for) a similar question here:

https://forums.coronalabs.com/topic/67239-how-to-repeat-a-fall/#entry347850

Thank you very much. It solved the problem. 

Hi @raresrap,

There are various ways to handle this. You could either create an invisible “floor” (physics sensor object) that is somewhere off the bottom of the screen, then detect collision with it and send the falling object back to the top. Or, you could track the position of the falling object in a Runtime listener function and, when it gets below a certain y position, send it back to the top.

Hope this helps,

Brent

I’ve made a floor but in I think I’m not doing the collision right.

 

–floor

local podea = display.newImage(“floor.png”)

podea.x=0

podea.y=1100

physics.addBody(podea, “static”)

local function onCollision(event)

if event.phase == “began” then 

if event.object1.name == “bara”

then transition.moveTo( bara, { x=140, y=150 } )

end

end

end

Runtime:addEventListener(“collision”, onCollision)

Hi.  Is this for a class?  I ask because I just answered (or gave starter code for) a similar question here:

https://forums.coronalabs.com/topic/67239-how-to-repeat-a-fall/#entry347850

Thank you very much. It solved the problem.