Hello, so I’ve been trying to move a model, so that the center of the bounding box of the model is at the origin (0,0,0). I need this to work regardless if the model has a PrimaryPart or not.
I have checked out some other threads with the same problem, and they pointed out model:SetPrimaryPartCFrame() and model:MoveTo(), which are not what I want, as they either rely on a primary part or an assembly root and my model isn’t guaranteed to have those.
Thanks in advance.
How are your Models created then? You can only position a Model using model:SetPrimaryPartCFrame(). If you set the CFrame, then it will only move one particular part. Otherwise, you would have to establish the offset of each Part from a Primary which sounds messy
I don’t know if you want this to be used in game or just in studio. Regardless I made a function to move a model from the center.
function moveModel(model, destination: CFrame, shouldDelete)
if shouldDelete == nil then shouldDelete = true end
local oldPrimary = model.PrimaryPart
--creates invisible bounding box as the primary part
local box = Instance.new("Part", workspace)
box.Transparency = 1
box.Name = "modelBox"
box.CFrame, box.Size = model:GetBoundingBox()
box.Parent = model
model.PrimaryPart = box
model:SetPrimaryPartCFrame(destination)
--deletes the invisible bounding box if u dont want it
if shouldDelete then
model.PrimaryPart = oldPrimary
box:Destroy()
end
end
--Setting model origin to (0, 0, 0)
moveModel(modelHere, CFrame.new())
Let me know if it’s being used in-game or in studio