Help with Lua

I’m fairly new to the Lua Language, but I understand the basics of it to start creating a game in it like angry birds such and such. But I came to this point. I have a baby (fake) that is to be shot over a wall into the stroller on the opposite side of the phone screen. (using corona for simulator). What I want is when the baby comes within a certain distance of the stroller or touches the stroller it will cause finish the level and show a menu that says go on to the next level. But I do not know how to create the trigger that says 

“when baby comes within 1 unit of the stroller then do this”.

If you need my code just comment and I will post my code but please help me. 

Create invisible circle around stroller and make it detect collision with baby.

Piortz55… Do you have example code of how to make it detect collison? Read the first part of my post im fairly new to this language. I am usually using java, html, c++, c#, javascript. I do play minecraft (because I am 14) and there is a mod on there called computer craft which litteraly lets you make computer programs in lua. Thats how I heard about lua then I was wondering how to build an indie game for the xbox and on this website it had a video of how to make angry birds in 30 minutes so I watched it over and over until I had a good understanding of it and then tried it myself and now I decided to create a game for the andriod and IOS. 

Ah sorry missed this part. So read this ones

http://developer.coronalabs.com/content/game-edition-box2d-physics-engine

http://developer.coronalabs.com/content/game-edition-collision-detection

I know how to do the physics part, but would I make this circle/rectangle dynamic or static?

local physics = require( "physics" ) physics.start() --physics.setDrawMode("hybrid") -- uncomment this line to see physics objects (even this invisible) local floor = display.newRect(0, display.contentCenterY + 100, 1000, 10) floor:setFillColor( 0, 0, 255 ) local wall = display.newRect(0, 0, 20, 100) wall:setFillColor( 255, 20, 0 ) wall.x = display.contentCenterX wall.y = display.contentCenterY local baby = display.newCircle( 0, 0, 10 ) baby:setFillColor( 0, 255, 0 ) baby.x = display.contentCenterX - 100 baby.y = display.contentCenterY + 40 baby.name = "baby" local stroller = display.newRect( 0, 0, 50, 50 ) stroller.x = display.contentCenterX + 100 stroller.y = display.contentCenterY + 40 physics.addBody( floor, "static", {} ) physics.addBody( wall, "static", {} ) physics.addBody( baby, "dynamic", {radius = 10} ) physics.addBody( stroller, "dynamic", {}, {radius = 100, isSensor = true} ) function stroller:collision( event ) if event.phase == "began" and event.other.name == "baby" and event.selfElement == 2 then local nextLevel = display.newText( "Go to next level", 50, 50, native.systemFont, 15 ) physics.pause() end end stroller:addEventListener( "collision", stroller ) baby:applyForce(0.35, -1, baby.x, baby.y)

Will the code you put make up for this… 

----------------------------------------------------------------------------------------- -- -- level1.lua -- ----------------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- include Corona's "physics" library local physics = require "physics" physics.start(); physics.pause() physics.setScale(35) -------------------------------------------- -- forward declarations and other locals local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth\*0.5 ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view --If the baby touches the Stroller local storyboard = require "storyboard" -- load menu screen -- create a grey rectangle as the backdrop local background = display.newRect( -50, 0, 1000, 850 ) background:setFillColor( 216, 128, 4 ) -- make a crate (off-screen), position it, and rotate slightly local baby = display.newImageRect( "baby.png", 35, 35 ) baby.x, baby.y = 45, -55 baby.rotation = 0 -- add physics to the crate physics.addBody( baby, { density=1.0, friction=0.3, bounce=0.1 } ) -- Making the baby be able to be shot function babyTouched(event) if event.phase == "began" then display.getCurrentStage():setFocus(baby) elseif event.phase == "ended" then baby:applyLinearImpulse(event.xStart - event.x, event.yStart - event.y, baby.x, baby.y) display.getCurrentStage():setFocus(nil) end end baby:addEventListener("touch", babyTouched) --Stroller local stroller = display.newImageRect( "babyStroller.png", 50, 50 ) stroller.x, stroller.y = 425, 218 stroller.rotation = 0 --Stroller physics physics.addBody( stroller, "dynamic", {}, {density=1.0, friction=0.3, bounce=0.3, isSensor=true} ) --collision circle for the stroller function stroller:collision( event ) if event.phase == "began" and event.other.name == "baby" and event.selfElement == 2 then local nextLevel = display.newText( "Go to next level", 50, 50, native.systemFont, 15 ) physics.pause() end end stroller:addEventListener( "collision", stroller ) baby:applyForce(0.35, -1, baby.x, baby.y) --Wall local wall = display.newImageRect( "Wall.png", 50, 100 ) wall.x, wall.y = 185, 188 wall.rotation = 0 --Side Walls local sideWall = display.newImageRect( "SideWallA.png", 100, 1000) sideWall.x, sideWall.y = 5, 100 sideWall.rotation = 0 local sideWallB = display.newImageRect("SideWallA.png", 100, 1000) sideWallB.x, sideWallB.y = 500,100 sideWallB.rotation=0 --Wall physics physics.addBody( wall, "static", {density=1.0, friction=0.3, bounce=0.3}) --Side A/B physics.addBody( sideWall, "static", {density=1.0, friction=0.3, bounce=0.3}) physics.addBody( sideWallB, "static", {density=1.0, friction=0.3, bounce=0.3}) -- create a grass object and add physics (with custom shape) local grass = display.newImageRect( "grass.png", screenW, 82 ) grass:setReferencePoint( display.BottomLeftReferencePoint ) grass.x, grass.y = 0, display.contentHeight -- define a shape that's slightly shorter than image bounds (set draw mode to "hybrid" or "debug" to see) local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 } physics.addBody( grass, "static", { friction=0.3, shape=grassShape } ) -- all display objects must be inserted into group group:insert( background ) group:insert( grass) group:insert( baby ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view physics.start() end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view physics.stop() end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view package.loaded[physics] = nil physics = nil end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene

My stroller was 2-part body (two pairs of {}). First one was empty so default settings were applied. Second part was circle with big enough radius (which radius parameter you deleted). What’s more I made this circle part isSensor to detect collisions with it but not ot interact physically. Set physics draw mode to “hybrid” to see whats going on

So in other words… the code that you put WILL make up for the code that I have? 

Because I just clicked new project on Corona and then clicked physics based game with a menu? So thats why I have all that code here.

Create invisible circle around stroller and make it detect collision with baby.

Piortz55… Do you have example code of how to make it detect collison? Read the first part of my post im fairly new to this language. I am usually using java, html, c++, c#, javascript. I do play minecraft (because I am 14) and there is a mod on there called computer craft which litteraly lets you make computer programs in lua. Thats how I heard about lua then I was wondering how to build an indie game for the xbox and on this website it had a video of how to make angry birds in 30 minutes so I watched it over and over until I had a good understanding of it and then tried it myself and now I decided to create a game for the andriod and IOS. 

Ah sorry missed this part. So read this ones

http://developer.coronalabs.com/content/game-edition-box2d-physics-engine

http://developer.coronalabs.com/content/game-edition-collision-detection

I know how to do the physics part, but would I make this circle/rectangle dynamic or static?

local physics = require( "physics" ) physics.start() --physics.setDrawMode("hybrid") -- uncomment this line to see physics objects (even this invisible) local floor = display.newRect(0, display.contentCenterY + 100, 1000, 10) floor:setFillColor( 0, 0, 255 ) local wall = display.newRect(0, 0, 20, 100) wall:setFillColor( 255, 20, 0 ) wall.x = display.contentCenterX wall.y = display.contentCenterY local baby = display.newCircle( 0, 0, 10 ) baby:setFillColor( 0, 255, 0 ) baby.x = display.contentCenterX - 100 baby.y = display.contentCenterY + 40 baby.name = "baby" local stroller = display.newRect( 0, 0, 50, 50 ) stroller.x = display.contentCenterX + 100 stroller.y = display.contentCenterY + 40 physics.addBody( floor, "static", {} ) physics.addBody( wall, "static", {} ) physics.addBody( baby, "dynamic", {radius = 10} ) physics.addBody( stroller, "dynamic", {}, {radius = 100, isSensor = true} ) function stroller:collision( event ) if event.phase == "began" and event.other.name == "baby" and event.selfElement == 2 then local nextLevel = display.newText( "Go to next level", 50, 50, native.systemFont, 15 ) physics.pause() end end stroller:addEventListener( "collision", stroller ) baby:applyForce(0.35, -1, baby.x, baby.y)

Will the code you put make up for this… 

----------------------------------------------------------------------------------------- -- -- level1.lua -- ----------------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- include Corona's "physics" library local physics = require "physics" physics.start(); physics.pause() physics.setScale(35) -------------------------------------------- -- forward declarations and other locals local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth\*0.5 ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view --If the baby touches the Stroller local storyboard = require "storyboard" -- load menu screen -- create a grey rectangle as the backdrop local background = display.newRect( -50, 0, 1000, 850 ) background:setFillColor( 216, 128, 4 ) -- make a crate (off-screen), position it, and rotate slightly local baby = display.newImageRect( "baby.png", 35, 35 ) baby.x, baby.y = 45, -55 baby.rotation = 0 -- add physics to the crate physics.addBody( baby, { density=1.0, friction=0.3, bounce=0.1 } ) -- Making the baby be able to be shot function babyTouched(event) if event.phase == "began" then display.getCurrentStage():setFocus(baby) elseif event.phase == "ended" then baby:applyLinearImpulse(event.xStart - event.x, event.yStart - event.y, baby.x, baby.y) display.getCurrentStage():setFocus(nil) end end baby:addEventListener("touch", babyTouched) --Stroller local stroller = display.newImageRect( "babyStroller.png", 50, 50 ) stroller.x, stroller.y = 425, 218 stroller.rotation = 0 --Stroller physics physics.addBody( stroller, "dynamic", {}, {density=1.0, friction=0.3, bounce=0.3, isSensor=true} ) --collision circle for the stroller function stroller:collision( event ) if event.phase == "began" and event.other.name == "baby" and event.selfElement == 2 then local nextLevel = display.newText( "Go to next level", 50, 50, native.systemFont, 15 ) physics.pause() end end stroller:addEventListener( "collision", stroller ) baby:applyForce(0.35, -1, baby.x, baby.y) --Wall local wall = display.newImageRect( "Wall.png", 50, 100 ) wall.x, wall.y = 185, 188 wall.rotation = 0 --Side Walls local sideWall = display.newImageRect( "SideWallA.png", 100, 1000) sideWall.x, sideWall.y = 5, 100 sideWall.rotation = 0 local sideWallB = display.newImageRect("SideWallA.png", 100, 1000) sideWallB.x, sideWallB.y = 500,100 sideWallB.rotation=0 --Wall physics physics.addBody( wall, "static", {density=1.0, friction=0.3, bounce=0.3}) --Side A/B physics.addBody( sideWall, "static", {density=1.0, friction=0.3, bounce=0.3}) physics.addBody( sideWallB, "static", {density=1.0, friction=0.3, bounce=0.3}) -- create a grass object and add physics (with custom shape) local grass = display.newImageRect( "grass.png", screenW, 82 ) grass:setReferencePoint( display.BottomLeftReferencePoint ) grass.x, grass.y = 0, display.contentHeight -- define a shape that's slightly shorter than image bounds (set draw mode to "hybrid" or "debug" to see) local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 } physics.addBody( grass, "static", { friction=0.3, shape=grassShape } ) -- all display objects must be inserted into group group:insert( background ) group:insert( grass) group:insert( baby ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view physics.start() end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view physics.stop() end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view package.loaded[physics] = nil physics = nil end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene

My stroller was 2-part body (two pairs of {}). First one was empty so default settings were applied. Second part was circle with big enough radius (which radius parameter you deleted). What’s more I made this circle part isSensor to detect collisions with it but not ot interact physically. Set physics draw mode to “hybrid” to see whats going on

So in other words… the code that you put WILL make up for the code that I have? 

Because I just clicked new project on Corona and then clicked physics based game with a menu? So thats why I have all that code here.