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

How exactly would I change the rotation of a part?

Asked by 9 years ago

So, in a script I'm making I want a part to have a constant rotation of (0, 0, 0). Unfortunately, I don't know how to change the rotation of an object through script. The current script I have is this:

function changed(Rotation)
    if script.Parent.CFrame ~= script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0,0) then -- if rotation is not (0, 0, 0) then
        script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0,0) -- make rotation (0, 0, 0)
    end
end

script.Parent.Changed:connect(changed) -- script.Parent is a part

So, I need a statement that will correctly change an object's rotation through script, without the math.pi mumbo jumbo (unless that's the only way to do it).

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

The easiest way to make an object have no rotation is to use this nifty like hack:

script.Parent.CFrame = CFrame.new(script.Parent.Position)

Your if statement is always true, by the way, because CFrame.Angles() applies a Rotation, it doesn't set the Rotation. In order to actually get the current Rotation of a part, you're going to have to look at its Rotation Vector3, or do math to the results of The components method of CFrame.

0
Why does changing the rotation have to be so complex in Lua? It should just be the same as position... whyOmustOitObeOme 7 — 9y
0
It's not complex at all, actually. The problem with setting Position and Rotation directly is that ROBLOX will then shunt the Parts upwards until there are no collisions. This can only be circumvented by using CFrame. adark 5487 — 9y
0
So, how would I get a value out of rotation, such as putting a part's rotation into a Vector3Value? whyOmustOitObeOme 7 — 9y
0
Vector3Value.Value = Part.Rotation --Rotation as a property IS a Vector3. adark 5487 — 9y
Ad

Answer this question