Page 1 of 2

Moving Layer Calculations

Posted: Sun Aug 17, 2014 2:35 pm
by Fuyu
Ok, so same as I some people are starting to use this calculation for their own levels, and honestly, who wouldn't want some accurate moving layers? So I'm taking part of my time to explain two calculations that I'm using for my project.

If you want to calculate the speed you want for a moving layer to reach a certain position in a certain time of your choice, use the calculation below:
32 * (NºBlocks) / (Desired time) / 65 = (Desired Speed)

Though, if you want to calculate the desire time based upon a certain speed, use this calculation instead:
32 * (NºBlocks) / (Desired Speed) / 65 = (Desired time)
PixelPest wrote:Btw if you want to use more exact numbers if syncing issues are a problem use 2500/39 instead of 65 or in LunaLua code just use lunatime.toSeconds()
Note that the desired time can be deduced by replacing them like in any polynomial operation. Hope this helped.

Re: Moving Layer Calculations

Posted: Sun Sep 14, 2014 8:30 pm
by Fuyu
Sorry for the bump but I would like someone to stick this thread, just like I requested once I posted this.

Re: Moving Layer Calculations

Posted: Tue Sep 16, 2014 10:48 am
by HeroLinik
Natsu wrote:Sorry for the bump but I would like someone to stick this thread, just like I requested once I posted this.
I agree. This is a helpful guide for any SMBX user, whether they are newbies or veterans, and it will save them time when trying to exact the speed/time of the moving layer. You should put the distance on there as well.

Re: Moving Layer Calculations

Posted: Tue Sep 16, 2014 10:54 am
by Fuyu
@castlewars: The distance is the NºBlocks.

Re: Moving Layer Calculations

Posted: Sun Sep 28, 2014 11:28 pm
by lighthouse64
Natsu wrote:Sorry for the bump but I would like someone to stick this thread, just like I requested once I posted this.
Well, It happened. :)

Re: Moving Layer Calculations

Posted: Sat Oct 04, 2014 6:24 am
by DatDude
Wait, what does the "*" stand for?

Re: Moving Layer Calculations

Posted: Sat Oct 04, 2014 6:28 am
by bossedit8
DatDude wrote:Wait, what does the "*" stand for?
That stands for Multiply. Like 2 * 10 = 20

Re: Moving Layer Calculations

Posted: Fri Nov 21, 2014 2:58 pm
by PROX
I usually just do it in my head through trial and error and it works just fine lol

Re: Moving Layer Calculations

Posted: Sat Jan 31, 2015 2:52 pm
by Mista Epic
I've created a quick VBS file to help with this so you don't have to go through a calculator and do this. Excuse me for not making it a .EXE but I don't know how to code in VBScript or how to wrap VBScript or convert it to VBScript.

Download

I should also mention that because it is a Windows-based code, it should only work on Windows. But maybe it works on Mac or Linux or whatever. I don't know.

Re: Moving Layer Calculations

Posted: Wed Apr 08, 2015 12:36 pm
by []Yaroslav269[]
Desired time in seconds?

Re: Moving Layer Calculations

Posted: Thu Apr 09, 2015 3:54 am
by crusher169
this just doesn't work for me for some reason, I keep trying it but it isn't accurate

Re: Moving Layer Calculations

Posted: Mon May 25, 2015 10:44 am
by Trace
wait, i dont get it. HOW am i supposed to calculate it?

Re: Moving Layer Calculations

Posted: Mon May 25, 2015 10:53 am
by RudeGuy
Trace42 wrote:wait, i dont get it. HOW am i supposed to calculate it?
Use the calculator and write the formula in the OP replacing what needs to be replaced. Is it really that hard?

Re: Moving Layer Calculations

Posted: Mon May 25, 2015 11:09 am
by Trace
what i get when i try that is what i always get: invalid Input

Re: Moving Layer Calculations

Posted: Mon May 25, 2015 11:11 am
by RudeGuy
Trace42 wrote:what i get when i try that is what i always get: invalid Input
Then what about using one of the milion of calculators in the internet?

Re: Moving Layer Calculations

Posted: Thu Oct 01, 2015 5:27 pm
by Drachenbauer
someone asked, if the time in secconds.
but got no answer...
i need this answer too.
i want to make an item move 1 block (32pix) up and needs 1 sec for this distance.
i calculated this and got a vaule with a long tail of didits after the comma...
speed: 0,4923076 (endless: the sequence 923076 will repeat forever after the comma)
is that right

Re: Moving Layer Calculations

Posted: Fri Oct 02, 2015 1:53 am
by RudeGuy
Drachenbauer wrote:someone asked, if the time in secconds.
but got no answer...
i need this answer too.
But it's so obvious, even the delay (the time) says that it's in seconds.
Drachenbauer wrote: is that right
Use just the first 4 numbers after the comma.

Re: Moving Layer Calculations

Posted: Sat Dec 19, 2015 4:00 pm
by Fuyu
I apologize to those that asked on this thread, but around a year and a half I left the forums because of studies. So now I'll try to answer as many questions as possible. If you have trouble with the calculation just let me know and I'll answer as soon as possible.

Re: Moving Layer Calculations

Posted: Sun May 22, 2016 3:15 am
by Quantumenace
If I had realized this thread was a sticky I'd have posted my findings here to begin with. It's actually a little more complicated than this. The game is run in "ticks" (equivalent to frames), the speed is measured in pixels per tick, and you can't have a fraction of a tick; the layer will move a distance equal to the speed*ticks. 1 block length is equal to 32 pixels.

What makes it dicey is that the number of ticks are a bit off from what is expected.
Spoiler: show
0.1 second = 7 ticks
0.2 = 14 ticks
0.3 = 21 ticks
0.4 = 27 ticks
0.5 = 33 ticks
0.6 = 40 ticks
0.7 = 47 ticks
0.8 = 53 ticks
0.9 = 59 ticks
1.0 = 66 ticks
1.1 = 73 ticks
1.2 = 79 ticks
1.3 = 85 ticks
1.4 = 92 ticks
1.5 = 99 ticks
1.6 = 105 ticks
1.7 = 111 ticks
1.8 = 118 ticks
1.9 = 125 ticks
2.0 = 131 ticks

8.0 = 521 ticks
No wonder it's so hard to prevent cycling layers from getting farther and farther off if you don't use the same speed and delay both ways. A 2 second delay isn't even the same as two 1-second delays!

The number of ticks for a given number of seconds appears to be:

(seconds*65)+1, rounded to the nearest ODD number if it ends in .5

Normally .5 is rounded to the nearest even number, but presumably it's rounded before the 1 is added, resulting in it rounding towards odd numbers instead.

In that case the distance moved (in pixels) is:

((seconds*65)+1, rounded to the nearest ODD number if it ends in .5)*speed

The extra 1 is what tends to throw off the timing of layers. For example, a speed of -1 for 2 seconds and a speed of 2 for 1 second moves the layer -131 and then +132, causing it to go further off by 1 each cycle.

However, moving it by -1 for 1 second and +2 for 0.5 seconds does work because the number of ticks for 1 second is twice the number for 0.5 seconds. Another solution is to split up the first delay, so you have the layer moving -1 for 1 second, then -1 for 1 second again, then +2 for 1 second.

Re: Moving Layer Calculations

Posted: Sun May 22, 2016 5:31 am
by HVMetal
This is probably the same but simplified with less math:

|Speed| * Delay * 2 ~ Nr. of Blocks => Speed ~ Nr. of Blocks / Delay * 2 => Delay ~ Nr. of Blocks / |Speed| * 2

The results wont be so accurate but people wont turn off "Auto Align" just to place the block 2.123 blocks away.
Speed= -2
Delay= 1
Then approx. the Nr. of Blocks will be 4 since |-2| * 1 * 2 = 4