How to have an object pass through the bottom of another object, but still be able to rest on top of it

I have two objects, a ball and a platform.

When the screen is touched, the ball’s linear velocity is set to make it jump.

function background:touch( event )    if event.phase == "began" then        print( "Touch event began on:bg " )        ball:setLinearVelocity( 0, -200 )        print ("linear velocity set")    end    return true end background:addEventListener( "touch", background )

I am trying to make a platform jumper like Doodle Jump and my platform logic is as follows.  If the ball has a negative y linear velocity than allow it to pass through platforms, but if it has a positive y linear velocity, then allow it to rest on platforms.

I tried to write this function with a listener to replicate the above, but it does not work.

function ball:getLinearVelocity( event ) local vx, vy = ball:getLinearVelocity() if vy \< 0 then physics.removeBody( platform ) if vy \> 0 then physics.addBody( platform, "static", { bounce=0.0, friction=0.3 } ) end background:addEventListener( "getLinearVelocity", ball )

Am I approaching this whole problem incorrectly or do I just have issues with my code?  If they are just code issues, how can I fix them?

Hi @amm7790,

The best way to handle one-sided platforms is to use the “physics contact”. This tutorial outlines the entire process and includes a sample project which you can use as a basis.

http://coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

Best regards,

Brent

Figured it out! Thank you!

Hi @amm7790,

The best way to handle one-sided platforms is to use the “physics contact”. This tutorial outlines the entire process and includes a sample project which you can use as a basis.

http://coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

Best regards,

Brent

Figured it out! Thank you!