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 |
|
|
|
| 04 Mar 2014 10:37 PM |
| http://wiki.roblox.com/index.php?title=GetMass_(Function) |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 18 Apr 2008 |
| Total Posts: 11529 |
|
|
| 04 Mar 2014 10:51 PM |
| Sorry, but you have been Ninja'd! |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 18 Feb 2014 |
| Total Posts: 232 |
|
| |
|
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
|
  |
| 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
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 7212 |
|
| |
|
|
| 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 |
|
|
|
| 19 Apr 2014 09:04 AM |
@Dr I learn something new every day, thanks!
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|