Log In  

Cart #yibotokg-0 | 2023-05-10 | Code ▽ | Embed ▽ | No License

Hello,

I'm new to pico-8 and coding in general, so there is probably something obvious that I am missing. I'm trying to both normalize my diagonal movement while also prevent the "jittering" that happens sometimes with pico-8 diagonals. I saw in a Lazy Devs Academy video that we can prevent jittering by setting the sub-pixel position to the center of the pixel on the first frame of diagonal movement. But when I try to implement that here, it stops my normalization from working on speeds above 0.707, and it won't move my pixel at all while the speed is <= 0.707. (cart currently has speed set to 0.7, so diagonal movement doesn't work).

Any idea why this is happening and how I can fix it?

Thanks for supporting a newb!

P#129591 2023-05-10 06:42

1

The problem is actually your definition of diag and prev_diag. Take off the local from diag and it'll work.

Local variables only exist within the scope for which they're defined. So when _update runs the first time everything works as expected right up until the function exits at which point diag and prev_diag cease to exist. When _update runs again in the next frame diag doesn't exist yet so prev_diag gets set to nil then diag gets reset to false. And this happens every frame so essentially it's as if every frame is the first frame of diagonal movement. Removing the local makes those into global variables so they'll persist between calls to _update and everything will work as expected.

The reason for the weird speed limit problem you had was that below a certain speed the pixel doesn't move far enough to leave the pixel it's already on and then it gets reset to the center of the pixel on the next frame.

P#129593 2023-05-10 08:16 ( Edited 2023-05-10 08:38)

Thanks so much!

P#129625 2023-05-11 06:52

[Please log in to post a comment]