Hello DevForum. Happy Early Holidays if you celebrate it!
I’m wondering, how can you rotate a model relative to a point, similar to ROBLOX Studio’s Control + R feature, without the use of a parent Model holding all the models.
My very poor drawing is trying to show the way I’m trying to apply rotation in green, the way I don’t want in red, and orange is the center point on which the models rotate on.
I’m don’t have as much experience with CFrame angles as I do with CFrames without any rotation data, most advice helps.
By using the function GetBoundingBox which returns a CFrame and the Vector3 Size value of the model, we are able to create a Hitbox for the Model (I’m assuming you don’t have one already) and use SetPrimaryPartCFrame to the Model so that we can apply our rotation. Here’s a code snippet I created for your usage. In my script I also respect if you already have a PrimaryPart set to the model, however I am not sure if this will work thoroughly.
Code Snippet
local Model = workspace.Model
local ModelCFrame, ModelSize = Model:GetBoundingBox()
local Hitbox = Instance.new('Part')
Hitbox.Name = 'Hitbox'
Hitbox.Transparency = 1
Hitbox.Size = ModelSize
Hitbox.CFrame = ModelCFrame
Hitbox.Anchored = true
Hitbox.Parent = Model
local OldPrimaryPart = Model.PrimaryPart
Model.PrimaryPart = Hitbox
Model:SetPrimaryPartCFrame(Model:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)))
Hitbox:Destroy()
Model.PrimaryPart = OldPrimaryPart and OldPrimaryPart or nil
If this is what you were looking for, please mark this as a ‘Solution’.
Thanks for the quick reply, this kind of gave me an idea on what I should be doing. Let me play around with it and see if I can get anymore help before I click a solution button.
From reading the qCmdUtl Plugin’s source code there is a button called ‘RotateGroup’ which does something which sounds like what you want.
Here’s some code which works without using SetPrimaryPartCFrame or requiring a PrimaryPart from the model.
Code Snippet
local Model = workspace.Model
local CenterPoint = Model:FindFirstChild('RotationPoint')
CurrenctCFrames = {}
for _, Part in pairs(Model:GetDescendants()) do
if Part ~= CenterPoint then
if Part:IsA('BasePart') then
CurrenctCFrames[Part] = CenterPoint.CFrame:ToObjectSpace(Part.CFrame) -- Calculate offset from the part to the swivel point
end
end
end
CenterPoint.CFrame = CenterPoint.CFrame * CFrame.Angles(math.rad(0), math.rad(90), math.rad(0)) -- Rotate the swivel point
for Part, CFrame in pairs(CurrenctCFrames) do
Part.CFrame = CenterPoint.CFrame * CFrame -- Update the part's CFrame to the Swivel Points CFrame * the offset we calculated earlier
end
If you need some explanation as to why this works, let me know!
If this is what you were looking for, please mark this as a ‘Solution’.
Happy holidays
Here’s a .rblx file for what I used to test this out: Lord_Superbithia.rbxl (13.6 KB)