Move Objects After They Appear Randomly

Im trying to make a brick fall from the sky and a player would have to avoid it…right now I am spawning a new brick at a random point and applying physics to it so it falls, but the main character of my game is effected by physics in the x direction which changes based on the accelerometer. This isnt working now because the bricks are falling at an angle based on the accelerometer too… 

I want to spawn the object, and then make it move down on the screen.

My problem with getting this to work is that i think I would need two functions…One to make them spawn(at a delay of 5000), and another to make it move down (using object.y = object.y - 1)with no delay. When I do this, it does not work though.

Here is my code now(with the physics, not the two function approach):

local function updateBlocks()

check = math.random(640)

    brick1 = display.newImage(“brick.png”, check, 0, true)

    brick = display.newImage(“brick.png”, check, -500, true)

    physics.addBody(brick)

end

timer.performWithDelay(5000, updateBlocks, -1)

Thanks

Hi willgomolka99,

Depending on other (potential) design considerations down the road, you can selectively turn off world gravity on a specific physics object using the “.gravityScale” property. Then, you can “fake” a separate gravity-like effect on that object by applying force to it in a Runtime listener. This would theoretically allow you to have your bricks fall under normal gravity, while not being affected by the world gravity (which you have set to both downward Y and also X based on the accelerometer, correct?)

http://docs.coronalabs.com/api/type/Body/gravityScale.html

Brent

Hi willgomolka99,

Depending on other (potential) design considerations down the road, you can selectively turn off world gravity on a specific physics object using the “.gravityScale” property. Then, you can “fake” a separate gravity-like effect on that object by applying force to it in a Runtime listener. This would theoretically allow you to have your bricks fall under normal gravity, while not being affected by the world gravity (which you have set to both downward Y and also X based on the accelerometer, correct?)

http://docs.coronalabs.com/api/type/Body/gravityScale.html

Brent