Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Intense math (sin/cos)?

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

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

4 comments

0

Is it proven to be more script efficent to do this '' local sin,rad=math.sin,math.rad ''

0

I can't get it to rotate the other direction at all tries. I also cant go from bigger to smaller.

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.

0

For some reasons, I can tell when going from a bigger value to smaller, it starts right away, not smoothly.. Sometimes its reverse.

This discussion is preserved as it was. New answers, comments, and votes are closed.