Arcade Physics Stuck In Wall If Jumping While Moving

https://johncarrott.tinytake.com/tt/NDYyMjI3N18xNDY0OTczNg

I’m having an issue with Arcade Physics as shown in the video above. I have a player sprite colliding with “blocks” or “tiles”. Each block has its own physics body. Everything works fine until I try to jump and move left or right at the same time…but only when there are 2 blocks on top of each other…It’s hard to explain, but it’s shown well in my video. It gets stuck in between the 2 blocks like there is an invisible ledge in between them…I can let go of the jump key but as long as I’m holding the left or right key, it stays put…body.touching.down outputs true when I’m stuck there, so it sees some form of ground or solid collision beneath me while I’m in this situation. And it only happens when 2 blocks are on top of each other. If there are more blocks above the 2, it doesn’t happen…only on the top 2…I can’t combine the physics bodies either, because each one has it’s own logic and they will all be breakable and placable (a tiny dynamic sandbox world)…And changing the random world generation to have less features/steepness doesn’t help because if somebody places a block on top of another one, they’ll just run into the same problem. I’d love any help or insight anyone can provide.

You need to modify checkCollision to remove all of the interior edges (where blocks meet).

Thank you. It wasn’t exactly that, but it solved part of the issue and got me in the right direction and I ended up fixing it. I did what you recommended, but then I was moving into walls sometimes. I fixed this by setting my player’s y velocity to a positive value (the right amount to make the player fall naturally) and at the same time I set my player’s x velocity to 0 after these specific collisions (no more chance that you’ll move into a wall. The effect is a natural fall as if the wall has no friction when you jump into it. You hit the wall and fall. Everything works as expected now.

1 Like

For anyone who finds this thread in the future after encountering a similar issue, I also figured out I could just check for the collision and then set the “leftdown” or “rightdown” variable (that gets set to true when the right key is down and set to false when its up) = false. I figured out that it only happens while I was still holding down the move (left or right) key. Manually setting it to false means the player has to press the key again to start moving in that direction again. Kinda like if you hit a wall in real life. The player can no longer latch onto the side of stacked blocks, and I also don’t have to set velocity or the collisions of specific blocks. This approach takes much less code as well.