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

Rotate a model and parent children around center of model

Asked by 10 years ago

Hi guys; I want to be able to rotate a model around the center of its self. I have this script but it rotates the model around an axis and not the center of the model. Can anyone help me. Thanks

function onClicked()
    rotation=true parts=game.Workspace.Clay_Paky_K20_Beye.Pan:GetChildren() 
    for i=1,#parts do if parts[i]:IsA("Part") then 
        parts[i].CFrame=parts[i].CFrame + Vector3.new(0,0,0) 
        if rotation==true then 
            parts[i].CFrame=CFrame.Angles(0,0.01,0) * parts[i].CFrame 
            else 
        end 
    end 
    end



end

script.Parent.MouseButton1Down:connect(onClicked)

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago
function Transform(model, center, new)
    for _,v in pairs(model:GetChildren())do
        if v:IsA("BasePart")then
            v.CFrame=new*center:inverse()*v.CFrame
        end
        Transform(v,center,new)
    end
end

This will transform model by the difference between center and new, new being the new rotation.

Ad

Answer this question