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?
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