Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Intense math (sin/cos)?

Asked by
Nickoakz 231 Moderation Voter
9 years ago

I am trying to make a nice number tween service. Like so.

for a=from,to do
set.Rotation=from+1
wait()
end 

I want to be able to have the number start slowly, speed up, and slow down before stopping.

I like the curve but I want to be able to start with a custom number, curve, and stop at the final number in a transition.

My brain hurts after attempting to Google this question.

Like this..

Graph!

Where a would be the value to loop set the rotation of the gui? and (0,from) would be the start and (1,to) would be the end.

1 answer

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

What you're asking for is indeed a sine wave. sin(x) starts at 0, accelerates up to half the square root of 2 and then decelerates up to 1 over the domain of pi/2 radians (90 degrees).

The simplest solution is to use sin(x) from 0 to 90 degrees as a multiplier to tween from a to b.

Say the gui is rotated 45 degrees and you want it to go to 90:

local from=45
local to=90

local sin,rad=math.sin,math.rad
for i = 0, 90 do
    set.Rotation = from + sin(rad(i))*(to - from)
    wait()
end
0
Is it proven to be more script efficent to do this '' local sin,rad=math.sin,math.rad '' Nickoakz 231 — 9y
0
I can't get it to rotate the other direction at all tries. I also cant go from bigger to smaller. Nickoakz 231 — 9y
0
It's insignificant how much more efficient it is to declare library variables on the stack. It just makes it easier to read. To make it rotate in the other direction, `to` has to be smaller than `from`. 1waffle1 2908 — 9y
0
For some reasons, I can tell when going from a bigger value to smaller, it starts right away, not smoothly.. Sometimes its reverse. Nickoakz 231 — 9y
Ad

Answer this question