This is my code snippet for 8-dir movement in PICO-8. There are some in BBS like this but I think I have something to add here because:
1 - It doesn't move faster when going diagonals;
2 - It can move at speeds below 1 pixel/frame (sub-pixel movement);
3 - And most importantly: IT DOESN'T HAVE ANY ANNOYING JITTERING (the staircase effect)!!!
Feel free to scrutinize my code and give me any constructive tips. I am still getting started with PICO-8 and Lua.
"Either my memory is wrong or browser/pico8 changed, but now the movement is jittery. Not an up-and-down staircase effect but a back and forth along the diagonal."
Not back and forth, but maybe stuttering. This is not an issue. It happens because the speed on the demo is 0.75. If speed is below 1, it means sometimes you don't move this frame. The position is drawn to the rounded values of x and y, which are floating point numbers.
In fact, if speed is equal to any non-integer value, you might think the character's movement is stuttering, like the framerate is inconsistent, when in fact a non-integer speed only means that you don't move a fixed amount of pixels each frame, which can make you feel unconfortable, but mathematically is correct.
@merwok, I dunno what to tell you. I even recorded the movement of the pixel in video and watched it frame by frame to try to detect any backsteps.
The demo below is the exact same but here speed is equal to sqrt(2). This makes xspd and yspd equals to 1 when going diagonals, which is very pleasant to the eye, and equals to 1.41 when going horizontal and vertical, which causes a stuttering effect.
[Please log in to post a comment]