How can I move a model via the center of the model?

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().

As you can see, I’ve moved the model to me to see what was up and that happened.

It’s messing up my renders for models:

Here’s the main source:

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.

Thanks for any feedback!

1 Like

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.

have you tried :MoveTo()? If you dont know what that is, Here’s a link that might give you more info on it.

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.

https://developer.roblox.com/en-us/articles/understanding-root-parts
this link explains what root parts are.

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.

MoveTo should move the Model from it’s origin (local position of 0,0,0) iirc

try using this function

Sorry but I didn’t understand, could you elaborate on “from it’s original”?

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?

The swords are multiples parts together, every part you see is separate. (Blade, Handle, Hilt, etc)

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 default PrimaryPart on the server for players. On the client (using ViewPortFrames), I wish to set a PrimaryPart to the exact center of the Model OR 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.

Yes but the model will have an offset because the PrimaryPart is not in the center of the model.

well the thoughts i’ve have about what your trying to accomplish is

  1. 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
  2. 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.

edit: i’ve found this post: https://devforum.roblox.com/t/how-to-find-the-vector3-center-of-a-model/267114/2, and from what i got from #2 of the post, @Operatik said,

so it could be the PrimaryPart is the exact center point.

1 Like

Another way is to use :GetBoundingBox() but as you can see for some reason it’s not working. I’ll look into that. Thanks