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

More efficient method of rotation?

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

1 comment

0

As you can see, it's quite bulky and inefficient.

3 answers

✓ Accepted answer

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

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

3 comments

0

Probably would be much more complex with loops.

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.

1

Thx eye cancer healed

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.

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