I was looking into GetBoundingBox(), and recently I’ve used it to find the center of my models then set PrimaryPart to a new part and then do :SetPrimaryPartCFrame().
preloadModels = function()
-- Loading Cameras
local objRenderCamera = Instance.new("Camera")
objRenderCamera.Name = "Object Render Camera"
objRenderCamera.CFrame = CFrame.new(0, 1000, 0)
objRenderCamera.Parent = workspace.World["Render Cameras"]
-- Preloading
for item, data in pairs(Dictionary) do
if ReplicatedStorage.Assets:FindFirstChild(data.Category.."s") and data.Category ~= "Skill" then
local copyItem = ReplicatedStorage.Assets[data.Category.."s"][item]:Clone()
copyItem.PrimaryPart.Anchored = true
local cframe, size = copyItem:GetBoundingBox()
local newPart = GlobalFunctions.new("Part", {
Transparency = 1,
Name = "CenterPart",
Anchored = true,
['CFrame'] = cframe,
["Size"] = size,
CanCollide = false,
Parent = copyItem,
})
copyItem.PrimaryPart = newPart
copyItem:SetPrimaryPartCFrame(objRenderCamera.CFrame * data.CFrame)
copyItem.Parent = workspace.World["Render Models"]
end
end
--> Set Item Info Camera To OBJRender
InfoFrame.SelectedItem.Frame.ViewportFrame.CurrentCamera = objRenderCamera
updateHotbar()
end,
So my question is obviously: How can I fix this or, is there an alternative way I can move a model based off the center without having to get the center then setting PrimaryPart.
Still no luck! Does anyone know why this might be occurring? I thought one of my sword models was broken somehow so I deleted it previously but now I load in large quantities of swords the problem seems clear.
I’ve read the link but what is the “RootPart”? Is it the center? My goal is to move the entire models via the center of it without setting PrimaryPart which I have to create a part to set.
It states that RootPart is basically the largest part. This will not work for me because for swords the blade will always be the largest. I need to move the model from the center. Thanks though.
are you creating swords that are just a part with a mesh inserted or is it parts that are shaped differently and make up seperate parts of the sword, like a part for the hilt, and a part for the blade?
if its made up of different parts, the center of the model would be inbetween both the hilt and 25% of the blade, that is the bottom of the blade. So are you wanting to move the sword via the center of the model, or another part that would make sense to be the PrimaryPart, like the Handle?
The handle is the defaultPrimaryPart on the server for players. On the client (using ViewPortFrames), I wish to set a PrimaryPart to the exact center of the ModelOR move the Model to a position or cframe using the center of the Model.
Also each blade is designed differently, sometimes the blade won’t have a hilt. I’d like to keep this as simple as possible and avoid setting a CFrame offset for every weapon.
you might be able to use a Vector3Value(not sure if that would work) and set it to 0, 0, 0, then set the PrimaryPart’s Vector3Value to that number, and that could position it in the exact center.
well the thoughts i’ve have about what your trying to accomplish is
it wouldnt be centered because of the possibility that when you move the PrimaryPart to the center, it could not move the other parts along with it, resulting in it being dispositioned
its impossible because i have no idea how you would find a models exact center point and position the PrimaryPart to the center point without dispositioing the other parts and making it look uneven, from a vertical point of view.
i will try to search around and see if its possible to find a models exact center point, because i am very confused about this.