I need a variable go in a zig-zag

i have a variable that goes up like a timer, and i need to use it to make another variable that goes like…

image

in a zig-zag motion. i need it. right now.

If you want to do it using only “regular math”:

With a little bit of experimentation, I was able to get this:

Unfortunately, I can’t find sin in blocks sin is available in blocks; pi is exposed in the arcade-sprite-utils extension.

Using a piece-wise function, I was able to get this:

It should be easy to implement in blocks, as mod is in blocks. (as the remainder of [ num ] / [ num ])

Share link to the equations: https://www.desmos.com/calculator/skuazm3gad

2 Likes

sinywave

oh boy do we got sine’s

2 Likes

@UnsignedArduino and how do I turn this into blocks?

@urassari like this?

1 Like

or if you really want it to be linear:

1 Like

Here’s what I did:

Had to modify the equations a bit to not use negative mod: (still exactly the same output) (as it’s funky in JavaScript)

@UnsignedArduino I’m so tired of my brain trying to understand how am I going to implement this to my game. https://arcade.makecode.com/S43710-98942-32379-76387 here is the game. Just… Fix it. Because I can’t.

1 Like

What have you tried? I don’t see an obvious place to put it.

i fixed it.

1 Like

here set the variable’s y to 2 *(((y1 / 2) * (x / x1 % 2)) - (y1 * (Math.floor(x/x1) % 2))) / (-1) ** Math.floor(x / x1);
were x = time since game start / speed
x1 is the horizontal distance between peek’s
y1 is the height the peek’s


i will try to make this formula simpler

1 Like

i did it here is the simpler version

y = (y1 / x1) * (((-1) ** floor(x / x1) * x) % x1)

1 Like

in total i made 3 versions that work

> asks for help
> can’t figure out the equasions
> fixes issue on his own, without any explanation
> refuses to elaborate
> leaves