Hi, i am learning to developing in Pico8, but i feel very frustating because i cant do a "perfect collisions" in a platformer 2d game. When i check the player position, the player stop 1 px before to the wall and if i cotinue pressing the button, the player can move a pixel more until to touch the wall (this happen with y velocity too).
Could you help me?? I apreciate a lot if someone can check the code and fix it :D
Your code is doing exactly what you told it to. If the player would end up in a wall when moved at current velocity, then the player's velocity is set to zero instead. This isn't a collision checking problem. It's a move to contact problem. I can think of two solutions off the top of my head:
-
Instead of always setting the velocity to 0, check if the velocity is above 1 and if so decrease it by 1 and then run the collision check again. Since you maximum speed is 2, that would take care of the situation where it takes another couple frames to get to the last pixel. The downside is that you'd need to convert to a proper loop if you ever want to allow faster movement.
- Set your player's position to the center of their current map tile relative to the relevant axis in any case where their movement would cause them to hit a wall. This wouldn't help if you decide to have other types of solids (such as pushable blocks), or if you make the player character smaller, but as long as you're using map tile size walls and a map tile size character it should work.
[Please log in to post a comment]