Getting center of mass of a model

I am looking for a way to get a models center of mass depending on the weight and mass of each part inside of that model. Where should I start? I have already looked at other forum posts about this topic, and I cannot find a good solution. This is where I’m at so far.

local mass, num = {},0 
for i, v in pairs(workspace.Model:GetDescendants()) do 
    if v:IsA("BasePart") then 
        table.insert(mass,i,v.Position)  
    end 
end
1 Like

That’s something very hard to do, I would look on the Internet how to get the center of mass of an object, I’m not sure how you would implement it in @Roblox but it’s better than nothing…

1 Like

Do you think I could get the average position of each part and multiply them by mass?

Nobody else has responded to this so I’m posting it not even 100% sure if it’s right, but try this:

In the Pirate Island template; workspace.Cutter.qShipManager:291

local function GetCenterOfMass(Parts)
	--- Return's the world vector center of mass.
	-- Lots of help from Hippalectryon :D

	local TotalMass = 0
	local SumOfMasses = Vector3.new(0, 0, 0)

	for _, Part in pairs(Parts) do
		-- Part.BrickColor = BrickColor.new("Bright yellow")
		TotalMass = TotalMass + Part:GetMass()
		SumOfMasses = SumOfMasses + Part:GetMass() * Part.Position
	end

	-- print("Sum of masses: " .. tostring(SumOfMasses))
	-- print("Total mass:    " .. tostring(TotalMass))

	return SumOfMasses/TotalMass, TotalMass
end
1 Like

I’m sorry. I made a repost since I did not do a very good job explaining my issue in this post. (I ended up just coding my own script for it and it worked somehow) I will mark your post as a solution for anybody else who comes by though.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.