Hi everyone, I've got a CFrame tool which I am close to completing to make it work for models. Any model that has a PrimaryPart will work fine when moving and rotating, but when I have a model without a PrimaryPart, I can move the model just fine, but rotating it causes the model to rotate frantically if I move one of the ArcHandles a bit. I have tried multiplying the axisAngle variable (near the bottom of the question) by a small Vector3, but this has led to only being able to rotate it to a certain point, so I got rid of it.
Below are my functions used to achieve the result above.
Model rotate function:
function TransformModel(objects, center, new, recurse) --This is used to rotate models without a PrimaryPart. Credit to Anaminus for the main function. for _,object in pairs(objects) do if object:IsA("BasePart") or object:IsA("PartOperation") then object.CFrame = new:toWorldSpace(center:toObjectSpace(object.CFrame)) end if recurse then TransformModel(object:GetChildren(), center, new, true) end end end
Get root model function:
function getRootModel(model) --This is used to get the root model for the selectedPose variable. The selectedPose variable is handled in a different function. if model.Parent:IsA("Model") and model.Parent.Parent == game.Workspace then return model.Parent elseif not model.Parent:IsA("Model") and model.Parent.Parent ~= game.Workspace then return getRootModel(model.Parent) elseif not model.Parent:IsA("Model") and model.Parent.Parent ~= game.Workspace then return nil end end
Main functions (for ArcHandles):
function onArcHandlesDown(normal) --This sets the previousCFrame variable for use when you move one of the ArcHandles. print("handlesDown") if selectedPose then previousCFrame = (selectedPose.PrimaryPart == nil) and selectedPose:GetModelCFrame() or selectedPose:GetPrimaryPartCFrame() moveHandlesPart.Position = (selectedPose.PrimaryPart == nil) and selectedPose:GetModelCFrame().p or selectedPose.PrimaryPart.Position moveHandlesPart.Size = (selectedPose.PrimaryPart == nil) and selectedPose:GetExtentsSize() or selectedPose.PrimaryPart.Size end end function onArcHandlesDrag(axis, relativeAngle, deltaRadius) --This is the main function. It handles the rotation for models with and without a PrimaryPart. if selectedPose and selectedPose.PrimaryPart then local axisangle = Vector3.FromAxis(axis) axisangle = axisangle * relativeAngle selectedPose:SetPrimaryPartCFrame(previousCFrame * CFrame.Angles(axisangle.X, axisangle.Y, axisangle.Z)) moveHandlesPart.Position = selectedPose.PrimaryPart.Position moveHandlesPart.Size = selectedPose.PrimaryPart.Size elseif selectedPose and not selectedPose.PrimaryPart then --This is the start of the statement which handles the rotation for models with no PrimaryPart. local axisangle = Vector3.FromAxis(axis) axisangle = axisangle * relativeAngle TransformModel( selectedPose:GetChildren(), previousCFrame, previousCFrame * CFrame.Angles(axisangle.X, axisangle.Y, axisangle.Z), true ) --This is the call to the first function to rotate the model. However, this makes the model rotate frantically. end end
Any help is appreciated, thanks!