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

How to make a model or part rotate about its origin/center?

Asked by 6 years ago

I recently made a successful script for a chest which flips open if you click on it. However, it rotates weirdly upon clicking. More like rotating around another point, instead of the object's center. Here is the script:


function onClicked(PlayerWhoClicked) script.Parent.Lid.CFrame = CFrame.Angles(math.rad(5), 0,0) end script.Parent.ClickDetector.MouseClick:connect(onClicked)

Is there any specific type of rotation I should use?

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Well we can use CFrame to do this

If our object is a model use :SetPrimaryPartCFrame() if a basepart then change its CFrame It will also check if the model has a primarypart so make sure it's set

local thing = workspace.Model

if thing:IsA("BasePart") then
    thing.CFrame = thing.CFrame*CFrame.Angles(math.rad(5), 0,0)
elseif thing:IsA("Model") and thing.PrimaryPart~=nil then
    thing:SetPrimaryPartCFrame(thing:GetPrimaryPartCFrame()*CFrame.Angles(math.rad(5), 0,0))
end

Now let's combine your script and this one I will also combine your function and where u call it

script.Parent.ClickDetector.MouseClick:connect(function(plr)
    local thing = script.Parent.Lid

    if thing:IsA("BasePart") then
        thing.CFrame = thing.CFrame*CFrame.Angles(math.rad(5), 0,0)
    elseif thing:IsA("Model") and thing.PrimaryPart~=nil then
        thing:SetPrimaryPartCFrame(thing:GetPrimaryPartCFrame()*CFrame.Angles(math.rad(5), 0,0))
    end
end)
Ad

Answer this question