Un-deprecate Model:GetModelCFrame()

As a Roblox developer, it is currently too hard to get the center point of a model without creating your own method to sort through all of the parts in a model, get the bounding box, and manually calculate the center point. Roblox already has a method for this but it has been deprecated and therefore should not be used in new projects. This means that, even though the method exists, I can’t use it in a game I am making- so I am going to have to implement my own solution.

The solution is pretty simple: either reinstate the GetModelCFrame() method to future support or recreate it if there’s a problem with the original version. It would save developers in this position a lot of time.

20 Likes

Support! This sounds like a super advantageous function.

I use it in one of my projects. It scares me that it is deprecated and might not be supported in the future. The method supplies a functionality that I am not able to program myself and it works quite well in my project currently.

1 Like

Honestly it’d just be easier to write your own code for it.

function getParts(m, t)
	t = t or {}
	for i,v in pairs(m:GetChildren()) do
		if v:IsA("BasePart") then table.insert(t,v) end
		getParts(v,t)
	end
	return t
end

function getModelCentre(model)
	local parts = getParts(model)
	local sX,sY,sZ
	local mX,mY,mZ
	
	for i,v in pairs(parts) do
		local pos = v.CFrame.p
		sX = (not sX and pos.X) or (pos.X < sX and pos.X or sX)
		sY = (not sY and pos.Y) or (pos.Y < sY and pos.Y or sY)
		sZ = (not sZ and pos.Z) or (pos.Z < sZ and pos.Z or sZ)
		
		mX = (not mX and pos.X) or (pos.X > mX and pos.X or mX)
		mY = (not mY and pos.Y) or (pos.Y > mY and pos.Y or mY)
		mZ = (not mZ and pos.Z) or (pos.Z > mZ and pos.Z or mZ)
	end
	
	return Vector3.new((sX+mX)/2,(sY+mY)/2,(sZ+mZ)/2)
end

print(getModelCentre(workspace.Model))
2 Likes

Support! I didn’t know it was deprecated

Read this thread:

https://devforum.roblox.com/t/why-is-getmodelcframe-deprecated/39521/14