Search code examples
androidlibgdx

libGDX: How I can create an one-way platform?


How can I create an one-way platform? I want to jump as player through the platform and land on it when the player's falling down. Thanks for every comment! :)


Solution

  • Break the problem up in pieces and the solution presents itself.

    • When player is going up and touching platfrom do nothing.
    • When player is going down and touching platform put him on top of it.

    The code depends on what you are using for collision. Something along these pseudo lines:

    if (collision)
    {
        if (velocity.y > 0) return;
    
        if (velocity.y <= 0)
        {
            player.y = platform.top;
            // and/or
            velocity.y = 0;
        }
    }