generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Calculate mass of an object and things attached to it?

Previous Thread :: Next Thread 
Netprobe is not online. Netprobe
Joined: 04 Aug 2011
Total Posts: 7212
04 Mar 2014 10:35 PM
I was thinking, and I realized how useful a script for finding the mass of things would be. I have plans to use it for optimization of thrust and torque stuff, but does anyone know how to find the mass of a model, it's children, and anything directly stuck to it(Player, cargo, etc.)?
Report Abuse
secretidagent is not online. secretidagent
Joined: 07 Nov 2010
Total Posts: 1600
04 Mar 2014 10:37 PM
http://wiki.roblox.com/index.php?title=GetMass_(Function)
Report Abuse
Azirux is not online. Azirux
Joined: 18 Feb 2014
Total Posts: 232
04 Mar 2014 10:48 PM
I don't think you can use that method on the model. Not 100% sure, but just a head notice.
Report Abuse
jd678 is not online. jd678
Joined: 18 Apr 2008
Total Posts: 11529
04 Mar 2014 10:50 PM
function getModelMass(Model)
local Mass = 0
for i,v in pairs(Model:GetChildren()) do
if v:IsA("BasePart") then
Mass = Mass + v:GetMass()
elseif v:IsA("Hat") then
Mass = Mass + v.Handle:GetMass()
end
end
return Mass
end

TotalModelMass = getModelMass(Workspace.Model)
print(TotalModelMass)
Report Abuse
secretidagent is not online. secretidagent
Joined: 07 Nov 2010
Total Posts: 1600
04 Mar 2014 10:50 PM
totalmass = 0
m=game.Workspace.Model:GetChildren()
for i=1,#m do
if m[i].ClassName == "Part" or m[i].ClassName == "WedgePart" then
mass = m[i]:GetMass()
totalmass = totalmass + mass
end
end
Report Abuse
jd678 is not online. jd678
Joined: 18 Apr 2008
Total Posts: 11529
04 Mar 2014 10:51 PM
Sorry, but you have been Ninja'd!
Report Abuse
Azirux is not online. Azirux
Joined: 18 Feb 2014
Total Posts: 232
04 Mar 2014 10:54 PM
I will burn you

mass = 0

function getMass(obj)
for i,v in pairs(obj:GetChildren()) do
if v:IsA("BasePart") then
mass = mass + v:GetMass()
else
getMass(v)
end
end
end

getMass(workspace.Model)
Report Abuse
jd678 is not online. jd678
Joined: 18 Apr 2008
Total Posts: 11529
04 Mar 2014 11:56 PM
Nice, you added a recurse, but what about returning the mass? :p
Report Abuse
jd678 is not online. jd678
Joined: 18 Apr 2008
Total Posts: 11529
05 Mar 2014 12:02 AM
I'm not sure if this would work, but if it did, it'd get the mass of parts, inside of models, etc., etc.


function getModelMass(Model)
local Mass = 0
for i,v in pairs(Model:GetChildren()) do
if v:IsA("BasePart") then
Mass = Mass + v:GetMass()
getNum = v:GetChildren()
if #getNum > 0 then
coroutine.resume(coroutine.create(getModelMass(v)))
end
elseif v:IsA("Hat") then
Mass = Mass + v.Handle:GetMass()
elseif v:IsA("Model") then
getNum = v:GetChildren()
if #getNum > 0 then
coroutine.resume(coroutine.create(getModelMass(v)))
end
end
end
return Mass
end

TotalModelMass = getModelMass(Workspace.Model)
print(TotalModelMass)
Report Abuse
Azirux is not online. Azirux
Joined: 18 Feb 2014
Total Posts: 232
05 Mar 2014 04:09 PM
NOOOOOOOOOOOO

ok u win
Report Abuse
Netprobe is not online. Netprobe
Joined: 04 Aug 2011
Total Posts: 7212
18 Apr 2014 11:47 PM
I'm about to use this. Which one of these scripts is right?
Report Abuse
Netprobe is not online. Netprobe
Joined: 04 Aug 2011
Total Posts: 7212
18 Apr 2014 11:48 PM
Oh, and if this were for say, a vehicle, would it get the player?
Report Abuse
Netprobe is not online. Netprobe
Joined: 04 Aug 2011
Total Posts: 7212
19 Apr 2014 08:33 AM
Well?
Report Abuse
DrMathematica is not online. DrMathematica
Joined: 29 Aug 2008
Total Posts: 27268
19 Apr 2014 09:01 AM
You guys do know there is a function (method) called :GetConnectedParts(), right?

All you need to do is pick a part you want, get the connected parts and then GetMass on all of them - adding it to a total. Basically:

local t = Workspace.Part:GetConnectedParts()
local am = Workspace.Part:GetMass()

for I,v in pairs(t) do
am = am + v:GetMass()
end

print(am)
Report Abuse
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
19 Apr 2014 09:04 AM
@Dr I learn something new every day, thanks!

Here's my siggy... Done.
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
19 Apr 2014 09:05 AM
"You guys do know there is a function (method) called :GetConnectedParts(), right?"
Yes. I`ve used it in my pathfinding.
I was going to suggest the same thing. However, this would only work if 1.) all the parts are connected to one central one or 2.) You used some recursion on it. The latter being quite time consuming/difficult.
Report Abuse
DrMathematica is not online. DrMathematica
Joined: 29 Aug 2008
Total Posts: 27268
19 Apr 2014 09:08 AM
"this would only work if 1.) all the parts are connected to one central one "

Is that not what the title asks for?
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
19 Apr 2014 09:13 AM
Indeed, but I like to assume that he`d like more flexibility with it.
Also, If you read the actual post "how to find the mass of a model, it's children, and anything directly stuck to it(Player, cargo, etc.)?"
"cargo" I assume isn`t just one block and Player is an obvious no.
Report Abuse
Netprobe is not online. Netprobe
Joined: 04 Aug 2011
Total Posts: 7212
19 Apr 2014 09:51 AM
Thanks lamp. I would do it myself, but I'm not really experienced at scripting, and kind of busy.
Report Abuse
Netprobe is not online. Netprobe
Joined: 04 Aug 2011
Total Posts: 7212
20 Apr 2014 10:31 AM
So wait, how do you make the script I need then?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image