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

More efficient method of rotation?

Asked by 8 years ago

So I have two unions which I can't union together, but I'm trying to get them to rotate 360* when the script is active, it works, but it is very inefficient.

sp = script.Parent
while true do
    sp.A.Rotation = Vector3.new(-180, -0, -180)
    sp.B.Rotation = Vector3.new(-180, -0, -180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, -15, -180)
    sp.B.Rotation = Vector3.new(-180, -15, -180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, -30, -180)
    sp.B.Rotation = Vector3.new(-180, -30, -180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, -45, -180)
    sp.B.Rotation = Vector3.new(-180, -45, -180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, -60, -180)
    sp.B.Rotation = Vector3.new(-180, -60, -180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, -75, -180)
    sp.B.Rotation = Vector3.new(-180, -75, -180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, -90, 0)
    sp.B.Rotation = Vector3.new(0, -90, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, -75, 0)
    sp.B.Rotation = Vector3.new(0, -75, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, -60, 0)
    sp.B.Rotation = Vector3.new(0, -60, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, -45, 0)
    sp.B.Rotation = Vector3.new(0, -45, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, -30, 0)
    sp.B.Rotation = Vector3.new(0, -30, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, -15, 0)
    sp.B.Rotation = Vector3.new(0, -15, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, -00, 0)
    sp.B.Rotation = Vector3.new(0, -00, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, 15, 0)
    sp.B.Rotation = Vector3.new(0, 15, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, 30, 0)
    sp.B.Rotation = Vector3.new(0, 30, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, 45, 0)
    sp.B.Rotation = Vector3.new(0, 45, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, 60, 0)
    sp.B.Rotation = Vector3.new(0, 60, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, 75, 0)
    sp.B.Rotation = Vector3.new(0, 75, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(0, 90, 0)
    sp.B.Rotation = Vector3.new(0, 90, 0)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, 75, 180)
    sp.B.Rotation = Vector3.new(-180, 75, 180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, 60, 180)
    sp.B.Rotation = Vector3.new(-180, 60, 180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, 45, 180)
    sp.B.Rotation = Vector3.new(-180, 45, 180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, 30, 180)
    sp.B.Rotation = Vector3.new(-180, 30, 180)
    wait(0.07)
    sp.A.Rotation = Vector3.new(-180, 15, 180)
    sp.B.Rotation = Vector3.new(-180, 15, 180)
    wait(0.07)
end
0
As you can see, it's quite bulky and inefficient. TheHospitalDev 1134 — 8y

3 answers

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

You're right about the weird way rotation shows in the output. If you type in 0, 91, 0 it will immediately get converted to -180, 89, -180, although the actual rotation will be correct. I'm not sure why this happens, it seems pretty weird to me.

But even though it gets converted to -180, 89, -180, that doesn't actually stop you from typing in 91. It doesn't matter that roblox immediately changes it, because the two rotations are equivalent.

Therefore, the following actually works (I just tested it):

for i = 1, 360 do
    script.Parent.Rotation = Vector3.new(0, i, 0)
    wait()
end
Ad
Log in to vote
1
Answered by
Uglypoe 557 Donator Moderation Voter
8 years ago

Iteration Loops! You can encase that all into two loops and make it much, much more friendly to all of our eyes!

Example:

sp = script.Parent
while true do
    for i=1,11 do
    sp.A.Rotation = Vector3.new(-180, 90-(i*15), -180)
    sp.B.Rotation = Vector3.new(-180, 90-(i*15), -180)
    wait(0.07)
    end
    for i=1,13 do
    sp.A.Rotation = Vector3.new(0, -105 + (i*15), 0)
    sp.B.Rotation = Vector3.new(0, -105 + (i*15), 0)
    wait(0.07)
    end 
end
0
Probably would be much more complex with loops. LifeInDevelopment 364 — 8y
0
Complex? Sure. Easier to read and therefore easier to optimize? Without a doubt. This is simply a start, he can make it much better from there. Uglypoe 557 — 8y
1
Thx eye cancer healed Dolphinous 36 — 8y
Log in to vote
-2
Answered by 8 years ago

Its fine, many developers use rotations like this (for example ScriptOn) instead of animations and other ways to rotate stuff. In many cases it might be smoother but its quite unlikely the client would lag from the script.

Answer this question