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

How can I Rotate Parts Around a Central Part and Maintain their original rotation?

Asked by 10 years ago

Okay, so for my script, I create a base part along with all the detail parts around it. This base part is used for the central position of the model and its rotation. There are template models that have a base part and preCFramed parts around that Base. So far, I have been able to correctly position all the parts around the base part. However, I am unable to take the CFrame of the new Base part into account with my current script, help!

What I currently have:

function AdjustPosition(Model, Type) --Root Part Called Base
    for i, v in pairs(Model:GetChildren()) do
        if( v.Name ~= "Base" and v:IsA("Part") )then
            v.CFrame = ( Templates[Type][v.Name].CFrame - Templates[Type].Base.Position) + Model.Base.Position
        end
    end
end

**Simple Request: **I want to rotate this CFrame (( Templates[Type][v.Name].CFrame - Templates[Type].Base.Position) + Model.Base.Position) by the rotation of the Model.Base.Rotation or whatever. How do?

1 answer

Log in to vote
1
Answered by 10 years ago

My method is to get the offset (difference in position and rotation) of all the parts from the "center" CFrame, and then add that offset to the new CFrame. It looks something like this:

function CFrameModel(Model, Center, DesiredCFrame)
    for i,v in pairs(Model:GetChildren()) do
        if v:IsA("BasePart") then
            v.CFrame = DesiredCFrame:toWorldSpace(Center:toObjectSpace(v.CFrame))
        elseif v:IsA("Model") then
            _G.CFrameModel(v,Center,DesiredCFrame)
        end
    end
 end
0
Could you walk me through the Center, v.CFrame and the Desired CFrame? Which of those is what in my code?? TheNickmaster21 0 — 10y
0
v = Current object in iteration, Center = Base, DesiredCFrame = New CFrame. Example: If you wanted to rotate everything inside of a model 45 degrees on the Y axis, you would do CFrameModel(Model, CenterPart.CFrame, CenterPart.CFrame*CFrame.Angles(0,math.rad(45),0)) Imaginaerum 30 — 10y
0
But, I have a template model with the ideal configuration. I want to be able to use a rotated and moved Base part and get the CFrames of the other parts using the different from the new Base CFrame and the Template Base CFrame... TheNickmaster21 0 — 10y
0
Excuse me, but what? Simple terms now; you want to rotate a model full of parts around the center of the model, correct? Chaotic_Cody 154 — 10y
View all comments (5 more)
0
False. I have a template model. It's an invisible part surrounded by CFramed 'Detail parts'. I place copy of this template and change the roation of the invisible Base part. I then want to rotate all the Detail parts in relation to the Base part. TheNickmaster21 0 — 10y
0
I tried using his rotation code and couldn't get it to work with mine. Check the epic failures on the RBXDev post... TheNickmaster21 0 — 10y
0
Why are you rotating the center first, and then rotating the rest? That makes no sense. Chaotic_Cody 154 — 10y
0
I'm fixating all the other points in relation to the Base part. So I can do simple translation on the Base part and replicate them with the adjustment script. TheNickmaster21 0 — 10y
Ad

Answer this question