Trying to get a Mario inspired platform game in order to teach platformer techniques. A major limitation is that there is only one type of wall so really need to check how (left or right) we are colliding with the wall. I had to add this change y by -1 to prevent my mushroom from getting stuck against the wall.
If you change the -1 to 0, you will see the stuck behavior. To trigger a mushroom, have Mario jump up into a block. FYI: the scoring is just to help the debugging.
Whenever a sprite hits a wall, all velocities stop. Unfortunately even setting the velocity in the opposite direction does not work within the same event block (however, changing the y position does get it to work).
In my games when a sprite hits a wall, I would go to all sorts of trouble to try and get it move in the opposite direction. For instance using the âsprite dataâ extension, storing the speed as data variable to the sprite, and using a âtimerâ method, I would then have the sprite move in the opposite direction after some time had passed.
Changing the Y value to move it off the wall works really well, although you do see it jump just a little.
The issue here is pretty subtle; itâs hitting the wall to the side, but is also hitting the wall to the bottom (due to the ay), and in both causing it call the âhits wallâ code twice â and in each case itâs hitting the wall to the left / right. Ideally you want to check is { location } to the left / right of { sprite }, but Iâm not sure we have a super easy way to do that right away, even with the tilemaps extension (besides manually comparing row / col). Several possible fixes for now:
instead of setting to vx*-1, just set a specific vx; hitting two walls in a row wonât matter as theyâll just be resetting vx to the same value:
If maintaining each enemies vx is important, you can clear ay when the enemy is standing on a wall and set it back whenever the enemy isnât standing on a wall: