Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i find the Weight of a Brick/Model?

Asked by
NexeusX 137
7 years ago

O'k so i am making a script that will go into bricks, so anyway i want the script to activate a function when "OnTouched" then find how much pressure is being put on the brick, and then if it goes past the limit ":BreakJoints()" so how can i find how much pressure/weight is being put on the brick?

0
Just use the size. It will be simpler that way. Perci1 4988 — 7y

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

Depends on your definition of weight. I will assume you mean mass, but if you want the force of gravity exerted by the brick/model, simply multiple the mass by the acceleration do to Gravity (game.Workspace.Gravity, where 196.2 is the default).

Calculating Mass

Getting the mass of a part is simple, as they all have the function GetMass.

As for getting the mass of a model, we are going to need a custom function for that. All you have to do is look for every descendant that inherits from BasePart and sum together the mass of all of these objects. This is most easily done using recursion:

function GetDescendantMass(parent)
    local sum = 0

    for _, child in ipairs(parent:GetChildren()) do
        if child:IsA("BasePart") then
            sum = sum + child:GetMass()
        end
        sum = sum + GetDescendantMass(child)
    end

    return sum
end

To use this function simply pass in the model you want to get the mass of as the argument.

0
Ah i see i did not know we had a GetMass function, thanks a lot NexeusX 137 — 7y
0
And as for getting the weight of everything on the part, I would recommend using a region3 positioned just above. Use workspace:FindPartInRegion3() counting only the parts inside that are unanchored and have no y velocity. cabbler 1942 — 7y
0
The Region3 wouldn't be perfect either; imagine a box sitting atop another box which is sitting on the button. The problem gets tricky here because you then have to consider the forces applied on parts applying force on the button. BlackJPI 2658 — 7y
0
I don't think so. There's no better solution anyway. cabbler 1942 — 7y
Ad

Answer this question