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

How does this sine wave script work and please explain each line mentioned?

Asked by 9 years ago

--- Line needing help on inicated by this -> --[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[

print("Tehgeek's weird sinewave loaded...")
n = 0
spd = workspace.SpeedSine
tab = {}
position = workspace.SineStart.Position
xx = position.x --[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
yy = position.y+10 --[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
zz = position.z --[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[

for i = 1, 20 do
p = Instance.new("Part")
p.Name = "BRICKSINE"
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.Parent = workspace
table.insert(tab,p)
end

while wait(0.1) do
if spd.Value ~= 0 then
n = n+1 
div = n/spd.Value  --[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
for i = 1, 20 do
v = Vector3.new(1+xx,math.sin((i/2)+div)*5+yy,i*2+zz)  --[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
tab[i].CFrame = CFrame.new(v)*CFrame.Angles(math.sin((i/2)+div-1), 0, 0)  -[[[[[[[[[[[[[[[[[[
--tab[i].Parent = workspace
end
end
end

1 answer

Log in to vote
1
Answered by
funyun 958 Moderation Voter
9 years ago

Let's see here. You have the position of this so-called "SineStart". Position is a Vector3 value. You store the individual x, y, and z values of the position, but you add 10 to the y value. I'm going to assume that "spd" is constantly .5. So, div is going to be n * 2, and n is going to be increasing by 1 every 10th of a second. Because "n" is always increasing, "div" is also increasing. Now, let's look at "v". We're adding 1 to SineStart's x value. We're then getting the sine of i/2. Sine can only be between 1 and -1, and as i/2 increases, sine will go between those values in a wave-like pattern. Like I said, "div" will constantly grow. Think of it as the algebraic function, y = 2x. A graph of that equation would just be a line going up. If you graph sin(x) + 2x, that's going to look like a wave going along that line. It's a wave that gets higher and higher, like the linear function. Multiplying this function by 5 will cause the slope to be even steeper than sin(x) + 2x. Finally, you add yy, which is SineStart's value + 10. Remember what you learned about y-intercepts. y = x + 5 is parallel to y = x, just 5 units up. Finally, let's look at the z value. That's i, an increasing value, multiplied by 2, times 5. Think of that as y = 2x + whatever, say, 5. Ok, so then we actually position each part with CFrame. We already went through the hell that is "v", so let's move on to the angles. We're rotating this part on the x axis only. "math.sin(i/2) + div" should look familiar. This time we're just subtracting "div" - 1.

And there you have it. You probably don't even understand anything that I just said, and neither would any other average person. Basically, think of numeric for loops as algebraic functions. When you see...

x = 0

for i = 1, 10 do
    x =(i * 2) + 5
    print(x)
end

...think of y = 2x + 5 in the domain of integers within the interval [1, 10].

Ad

Answer this question