Tutorial:Sine

In trigonometry, sine is a ratio, where all degrees ranging from 0 to 360° corresponds to a number between -1 and 1. When you graph out these values, you make a smooth continuous wave.

A Quick Note
This is not to be confused with the EasingStyle called sine. This is about the function in mathematics.

The Sine Converter
In Advanced Scripting, I explained what math.sin does. In case you aren't familiar, it converts degrees to the sine ratio. To do this, just insert this into your script. Replace x with a value in radians, and voila! You can access this variable at any time; of course, it has to be within the same block of code. You can do the same thing with cosine and tangent.

The Arc Sine Converter
An arc sine is a derivation of sine. Instead of the y value being between 1 and -1, the x value is. To the right is an arc sine graph.

Instead of using math.sin, use the following code. X should be in radians. Again, this also applies to arc cosine and arc tangent.

The Hyperbolic Sine Converter
Below is the code to a hyperbolic sine converter. Again, x should be in radians.

How can sine be used in Roblox?
Sine can be used in Roblox by making an item bob up and down smoothly. Imagine the x-axis is the point in time and the y-axis is the height of the object. Based on this, we know that we can create an object that smoothly floats.

Making the object float
Before we begin, make sure your part is anchored. Then, enter the following code

Allow me to explain some terms:


 * The third line will add 10 degrees to the number each time.
 * The next line will convert degrees to radians.
 * The next line will convert radians to sine.
 * Then, the part will change its y coordinate to Number3.
 * The "animation" will wait one-hundredth of a second before repeating the cycle.

You can change the basic properties of the sine wave like this:


 * To increase the frame rate, decrease the time in the delay and the number added to variable "Number" in the third line.
 * When you multiply the sine ratio in line 5, you are increasing its amplitude; in other words, you are making the block go higher. In this case, I am making the part go 4 times as high.
 * When you add to the sine ratio in line 5, you are setting its resting position. In this case, its resting position is at (0,10,0).
 * You can change the coordinates so that it would bob left and right, by setting its x value to "Number3."
 * The same thing can be achieved by using cosine instead of sine. (ie: math.cos(Number2) * 4 + 10)