Log In  

Hello everyone! I'm developing a platformer based on My Hero Academy and for some reason, my player is able to jump while touching a jump-through tile, when they should only be able to jump if they're on top of it.

Does anyone know why this happens?

Code for jumping:

--jump
if btn(❎) and player.landed then
 player.dy-=player.boost
 player.landed=false
end

Code for landing:

if collide_map(player,"down", flags.base) then 
 player.landed=true
 player.falling=false
 player.dy=0
 player.y-=((player.y+player.h+1)%8)-1

Cartridge below 👇

Cart #dusiwguya-0 | 2024-03-12 | Code ▽ | Embed ▽ | No License

P#142811 2024-03-12 15:16 ( Edited 2024-03-12 15:21)

1

Take a look at your collide_map() function, you will see that when you check for a "down" collision, it picks two pixels at your characters' feet to check if those pixels are on a "solid" block. This will be true when those pixels land anywhere on the block. You could either not allow your player to enter this solid block from any side, or you could take measures to detect when they're in this position and move them up to ground level.

It looks like you might be able to use a debug mode to draw the collision boxes to make more sense of this visually.

P#142814 2024-03-12 15:37

Thank you! I'll take a look into that. I do have debug mode implemented, and it draws a rectangle wherever my character is colliding, but it's kind of limited due to how it was created: it only draws a rectangle in the latest direction it's checked. When my player is moving sideways, the function doesn't have enough time to draw the downward collision.

P#142815 2024-03-12 15:49

[Please log in to post a comment]