How to know when 2 objects are touching / overlapping

Here’s what I’m trying to achieve in a hypothetical plane landing game:

  • I have a plane object

  • I have a ground object for the plane to land on

  • When the player tilts the device, I want the plane to fly left/right

  • If the plane is on the ground then it should not move left/right when tilted

I can’t figure out how to detect when the plane is on the ground. [import]uid: 8353 topic_id: 3414 reply_id: 303414[/import]

…should mention I’m using physics, bodies, etc. [import]uid: 8353 topic_id: 3414 reply_id: 10250[/import]

look here
http://developer.anscamobile.com/content/game-edition-collision-detection

this should work:
[lua]local plane = display.newImage( “plane.png”, 100, 200 )
physics.addBody( plane, { density = 1.0, friction = 0.3, bounce = 0.2 } )
plane.id = “the plane”

local ground = display.newImage( “ground.png”, 160, 420 )
physics.addBody( ground, { density = 0 } )
ground.id = “the ground”

local function onCollision( event )
if ( event.phase == “began” ) then

print( "began: " … event.object1.id … " & " … event.object2.id )

if((event.object1.id==“the plane” and event.object2.id==“the ground”) or (event.object1.id==“the ground” and event.object2.id==“the plane”)) then

– do some landing stuff

end if

elseif ( event.phase == “ended” ) then

print( "ended: " … event.object1.id … " & " … event.object2.id )

end
end

Runtime:addEventListener( “collision”, onCollision )[/lua]

of course you could just check x,y positions [import]uid: 6645 topic_id: 3414 reply_id: 10265[/import]

Thanks for the reply.

I did look at using the collision events and it should work as you suggest. I was thinking about setting a flag on the plane (e.g. isLanded) and checking this in the movement routine.

Dunno, for some reason it just didn’t seem very elegant but I’m new to Corona so I’m unsure of what the “best” solution is to some problems.

But it works so I’ll go with it!

Cheers for your help. [import]uid: 8353 topic_id: 3414 reply_id: 10286[/import]