Hi sindrekristiansen,
Do you only want to check if the ball has collided with the block or do you want any collision to change “playerInAir” to false?
If you want any collision to set it to false, I suggest changing your onCollision function to something simpler, like this:
function onCollision( event ) if ( event.phase == "began" ) then playerInAir = false end end
If you want to set “playerInAir” to false only when the block and ball collide, you must make sure that your block and your ball have the names set. Take a look at this example from the documentation:
local crate1 = display.newImage( "crate.png", 100, 200 ) physics.addBody( crate1, { density = 1.0, friction = 0.3, bounce = 0.2 } ) crate1.myName = "first crate" local crate2 = display.newImage( "crate.png", 100, 120 ) physics.addBody( crate2, { density = 1.0, friction = 0.3, bounce = 0.2 } ) crate2.myName = "second crate" local function onCollision( event ) if ( event.phase == "began" ) then print( "began: " .. event.object1.myName .. " and " .. event.object2.myName ) elseif ( event.phase == "ended" ) then print( "ended: " .. event.object1.myName .. " and " .. event.object2.myName ) end end Runtime:addEventListener( "collision", onCollision )
If you look at each crate, you will see that they have a property that sets their name. So for your block and ball, you would want to do something like this:
local ball = display.newImage( "ball.png" ) ball.myName = "ball" local block = display.newImage( "block.png" ) block.myName = "block"
This should work. Let us know if it doesn’t.