Make "Exceptions" in Physics Engine.

Hey guys! I started programming on Corona for the first time today, and I’m currently working on some physics. I have two questions, on pertaining physics, one sort of not.

The physics question:

I have three main objects here, “snow”, “foo”, and “ground”. How do I make it that snow always passes through the ground, but foo doesn’t?

W = display.viewableContentWidth H = display.viewableContentHeight -- Setting up the display constraints to ensure visual quality on all phones. local physics = require( "physics" ) physics.start() physics.setGravity( 0, 12 ) if 1 == 1 then local snow = display.newImage("snow.png"); snow.x = math.random( 0, W ) snow.y = -20 physics.addBody( snow, "kinetic", {density=1, friction=0.5, bounce=0.3 } ) end local foo = display.newImageRect("foo.png", 100, 100); foo.x = W \* 0.5; foo.y = H \*0.5; -- Sets up location of "foo" on screen (center). local ground = display.newImageRect("ground.png", W, H \* 0.1); ground.x = W \* 0.5 ground.y = H function foo:touch( event ) if event.phase == "began" then self.markX = self.x --Storing X location self.markY = self.y --Storing Y location elseif event.phase == "moved" then local x = (event.x - event.xStart) + self.markX local y = (event.y - event.yStart) + self.markY self.x, self.y = x, y end return true end foo:addEventListener("touch",foo); --Creates the event that happens when Foo is touched. physics.addBody( foo, "kinetic", {density=3, friction=0.5, bounce=0.3 } ) physics.addBody( ground, "static", {density=2, friction=0.5, bounce = 0.3} )

My second question pertains:

if 1 == 1 then local snow = display.newImage("snow.png"); snow.x = math.random( 0, W ) snow.y = -20 physics.addBody( snow, "kinetic", {density=1, friction=0.5, bounce=0.3 } ) end

What I really want to do with this code is create several different objects that look exactly the same and have the exact same properties falling from random parts of the top screen. I also want to add a delay between the creation of each, about half a second or do. 

In addition, I would like some additional help on collisions, or when two objects come in contact. I want that when the red box, “foo” comes in contact with the snow, then the game will be lost (I think I know how to incorporate the “losing screen” by myself). This may also be used for the snow as well, maybe some code that can delete each snow when it touches the “ground”.

I don’t want you guys to really code it for me, other than the collision part. Instead I would love for one of you guys to guide me through it a bit. I’m sort of confused on the most part.

Thanks!

For your first question you are interested in Collision Filters: http://docs.coronalabs.com/guide/physics/collisionDetection/index.html#filtering

For the 2nd question, I think most people tend to use a timer.performWithDelay() to call a spawn function periodically.  Though there won’t be randomness that way.   You should also learn about enterFrame listeners where you get an event 30 or 60 times per second and you can check a random number to see if its time to release a new spawn.

Rob

For your first question you are interested in Collision Filters: http://docs.coronalabs.com/guide/physics/collisionDetection/index.html#filtering

For the 2nd question, I think most people tend to use a timer.performWithDelay() to call a spawn function periodically.  Though there won’t be randomness that way.   You should also learn about enterFrame listeners where you get an event 30 or 60 times per second and you can check a random number to see if its time to release a new spawn.

Rob