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

How do you rotate a "Part", and have workspace as it's parent?

Asked by 10 years ago

How do you rotate a "Part"?? I want this to be a function, so it's a mousebuttondown, event.

Can you tell me how to make it rotate, at an axis, like what makes it rotate at a X axis, and what makes it rotate, at a Y axis.

2 answers

Log in to vote
2
Answered by
duckwit 1404 Moderation Voter
10 years ago

The rotation of a Part is specified by the rotation matrix component of the CFrame property, you can set the rotation of a Part using a MouseButton1Down event like-so:

mouse = player:GetMouse() --"player" is a reference to the player object
part = workspace.SomePart --The part that you want to rotate

mouse.MouseButton1Down:connect(function()
    part.CFrame = part.Position + CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))
end)

Where x, y, and z are the angles in degrees to rotate around each axis

If you want the effects of rotation to be cumulative (adding a bit on each time), then use this instead for the rotation line:

part.CFrame = part.CFrame * CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))
Ad
Log in to vote
0
Answered by 10 years ago
mouse = player:GetMouse() --"player" is a reference to the player object
part = workspace.SomePart --The part that you want to rotate

mouse.MouseButton1Down:connect(function()
    part.CFrame = part.Position + CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))
end)

Answer this question