Premium Features
Now let's implement platform blocks that you can jump through from below but land on from above.
Regular collision blocks stop movement from all directions. Platform blocks should:
Allow jumping through — No collision when moving upward
Support landing — Collision when falling from above
In Tiled, create a separate object layer for platforms. Export these separately from collision blocks.
Only check for collisions when the player is falling:
if (player.velocity.y > 0) { // Check platform collisions if (player.hitbox.position.y + player.hitbox.height <= platform.position.y) { // Player is above platform and falling player.velocity.y = 0 player.position.y = platform.position.y - player.height } }The key is checking if the player was above the platform in the previous frame — this prevents collisions when jumping up through them.
With platform blocks working, you can now create more interesting vertical level designs.
Comments
Want to participate?
Create a free Chris Courses account to begin
No comments yet, be the first to add one