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

Union wont turn properly on rotation script Help please?

Asked by 3 years ago
Edited 3 years ago

Hi, I'm trying to make a gear spin, its a union and the hitbox is a perfect square, but i have many issues. The starting orientation is 0, 0, 0. Firstly, It's not continually spinning, it only spins until ~90 degrees, after which point it just goes back and forth. Secondly, Its mathematically incorrect, it rotates 5.625 degrees every 0.125 seconds, this may seem random, but its 90 degrees divided by 16. The reason i put ~ on the 90 degrees on the first one is that the gear just glitches at 84.41, 180, 180, which is not 90 degrees, or a multiple of 5.625. notice that there is 180 where there should be a 0, that is also an issue

here's the script

while true do
    script.Parent.Orientation = script.Parent.Orientation + Vector3.new(5.625,0,0)
    wait(0.08)
end

if any glowing brain Albert einstein geniuses can figure this out, feel free to

1 answer

Log in to vote
0
Answered by 3 years ago

It's generally bad practice to directly set the Orientation property of instances, especially when we have so many other options with CFrames. Check out this example, below:

while true do
    wait()
    script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(5),0,0)
end

We first set the part's CFrame to its original value. Then, we multiply it by a rotated CFrame, using CFrame.Angles, which is the equivalent of CFrame.fromEulerAnglesXYZ. This is defined as:

Creates a rotated CFrame using angles (rx, ry, rz) in radians

Also note that, in my example, I rotate the part on the X axis. You're free to rotate it on whichever axis you require.

Ad

Answer this question