Ask coding questions

← Back to all posts
how to make a block?
MatthewX (152)

How do I make a block the player can jump on?

Comments
hotnewtop
mwilki7 (1130)

You will need at least 2 blocks.
1 block is a wall,
the other block is a player.

You have the player, now you just need a block.
I use this function to determine whether 2 blocks have collided:

function checkCollision(rect1, rect2)
{
    if (rect1.x < rect2.x + rect2.width &&
        rect1.x + rect1.width > rect2.x &&
        rect1.y < rect2.y + rect2.height &&
        rect1.y + rect1.height > rect2.y)
    {
        return true;
    }

    return false;
}

and call it with

if (checkCollision(player_block, wall_block))
{
    // Player is colliding with the block
}
Coder100 (15521)

Well, right now you will not be able to easily make a block because of how your level is set up.
Try this tutorial.

MatthewX (152)

@Coder100 um its really longis there a certain place to watch?

Coder100 (15521)

well making a platformer isn't super easy @MatthewX

Coder100 (15521)

I'll whip up a template for you instead @MatthewX

MatthewX (152)

@Coder100 um its in a different language -_-

Coder100 (15521)

its in p5.js which is easier @MatthewX

MatthewX (152)

@Coder100 this is rlly confusing, i was thinking if I can make the player rest on the platform based on corrdinates.

Coder100 (15521)

@MatthewX well that would be ideal, but remember there is also edge cases, like if the player hit the block but not on top of the block and below the block