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

Rotation script breaks?

Asked by
wackem 50
9 years ago

First of all, the block I'm rotating has a mesh in it. But the following code breaks when it gets to the rotation 90 on the Y axis

local b = script.Parent

while true do
    wait(.01)
    b.Rotation = b.Rotation + Vector3.new(0, 1, 0)
end
0
You put "wait(.01)" which would require the script to wait 1/100 of a second but the quickest wait possible is 1/60 of a second which is "wait(0)" FearMeIAmLag 1161 — 9y
0
I don't want it to rotate super fast :P wackem 50 — 9y
0
You were having it rotate 100 times a second which the roblox engine does not support, 1/60 is the shortest amount of time and "wait(0)" makes it wait 1/60th of a second. FearMeIAmLag 1161 — 9y

3 answers

Log in to vote
1
Answered by
Hero_ic 502 Moderation Voter
9 years ago

Its probably better to use CFrame and while wait(.01) do here is the overall result of the script.

local b = script.Parent
local rot = 0 -- Make a rotation variable

while wait(.01) do
    rot = rot + .01 -- Make it add on every .01 second
    b.CFrame =  CFrame.new(b.CFrame.X,b.CFrame.Y,b.CFrame.Z)  * CFrame.Angles(0,rot --[[set this to rot so it can rotate]] ,0)
end
--There you go!

Hope this helps!

Ad
Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

The reason why it doesn't work is because you are adding +1 to the rotation each time.

On Roblox, when rotating a part, once the Y rotation gets to 85, it looks like this:

--This is what the rotation looks like if you add 1 to the Y value each time
0,85, 0
0,86,0
0,87,0
0,88,0
0,89,0
0,90,0
-180,89,-180
-180,88,-180
-180,87,-180
-180,86,-180
-180,85,-180
Log in to vote
0
Answered by 9 years ago

I don't know how to entirely explain this, but I'll fix your code.

local b = script.Parent

while true do
    wait(.01)
    b.CFrame = b.CFrame * CFrame.fromEulerAnglesXYZ(0,1,0)
end
1
Its better to use CFrame.Angles instead of fromEulerAnglesXYZ Hero_ic 502 — 9y
0
It's the same thing, but whatever. systematicaddict 295 — 9y

Answer this question