how to monitor the position of falling object?

Hey Guys

I am now working on a small academic project, I would like to know how can I monitor the x y position of the falling physical object.

let say there are three square( the following codes). How can I monitor the x y position of square a b c so that some effect will be trigger when they pass through the bottom line.

[lua]physics= require( “physics”)
physics.start( )
physics.setGravity( 0, 5 )
e=50
a= display.newRect( 50, 50, 50, 50 )
a.x=50
a.y=100

b= display.newRect( 70, 70, 70, 70 )
b.x=120
by=100

c= display.newRect( 100, 100, 100, 100 )
c.x=220
c.y=100

local greenCollisionFilter = { groupIndex = -2 }
physics.addBody(a,“dynamic”,{density=0,friction=0,bounce=0,shape={-e,-e,e,-e,e,e,-e,e},filter=greenCollisionFilter})
physics.addBody(b,“dynamic”,{density=0,friction=0,bounce=0,shape={-e,-e,e,-e,e,e,-e,e},filter=greenCollisionFilter})
physics.addBody(c,“dynamic”,{density=0,friction=0,bounce=0,shape={-e,-e,e,-e,e,e,-e,e},filter=greenCollisionFilter})

z=display.newRect(5,470,320,5);
z.anchorX=0
z.anchorY=0
physics.addBody(z,“static”,{density=0,friction=0,bounce=0,shape={-e,-e,e,-e,e,e,-e,e},filter=greenCollisionFilter}) --left[/lua]

Hi @ryan_cws,

Try this

physics= require( "physics") physics.start( ) physics.setGravity( 0, 5 ) --physics.setDrawMode( "hybrid"); a= display.newRect( 50, 50, 50, 50 ) a.x=50 a.y=100 a.name = "boxA" b= display.newRect( 70, 70, 70, 70 ) b.x=120 by=100 b.name = "boxB" c= display.newRect( 100, 100, 100, 100 ) c.x=220 c.y=100 c.name = "boxC" physics.addBody(a,"dynamic",{density=0,friction=0,bounce=0}) physics.addBody(b,"dynamic",{density=0,friction=0,bounce=0}) physics.addBody(c,"dynamic",{density=0,friction=0,bounce=0}) z=display.newRect(5,470,320,5); z.anchorX=0 z.anchorY=0 z.name = "ground" physics.addBody(z,"static",{density=0,friction=0,bounce=0, isSensor = true}) --left local function onCollision( event ) if ( event.phase == "began" ) then if event.other.name == "boxA" then print(event.other.name.." hit "..event.target.name.." do some effect here" ) elseif event.other.name == "boxB" then print(event.other.name.." hit "..event.target.name.." do some effect here" ) elseif event.other.name == "boxC" then print(event.other.name.." hit "..event.target.name.." do some effect here" ) end end end z:addEventListener( "collision", onCollision )

Good Luck!

burhan

Hi @ryan_cws,

Try this

physics= require( "physics") physics.start( ) physics.setGravity( 0, 5 ) --physics.setDrawMode( "hybrid"); a= display.newRect( 50, 50, 50, 50 ) a.x=50 a.y=100 a.name = "boxA" b= display.newRect( 70, 70, 70, 70 ) b.x=120 by=100 b.name = "boxB" c= display.newRect( 100, 100, 100, 100 ) c.x=220 c.y=100 c.name = "boxC" physics.addBody(a,"dynamic",{density=0,friction=0,bounce=0}) physics.addBody(b,"dynamic",{density=0,friction=0,bounce=0}) physics.addBody(c,"dynamic",{density=0,friction=0,bounce=0}) z=display.newRect(5,470,320,5); z.anchorX=0 z.anchorY=0 z.name = "ground" physics.addBody(z,"static",{density=0,friction=0,bounce=0, isSensor = true}) --left local function onCollision( event ) if ( event.phase == "began" ) then if event.other.name == "boxA" then print(event.other.name.." hit "..event.target.name.." do some effect here" ) elseif event.other.name == "boxB" then print(event.other.name.." hit "..event.target.name.." do some effect here" ) elseif event.other.name == "boxC" then print(event.other.name.." hit "..event.target.name.." do some effect here" ) end end end z:addEventListener( "collision", onCollision )

Good Luck!

burhan