So, I have this model here:
I’d like to measure how high it is. How would I accomplish this?
Thanks, Xuefei.
Very basic, rugged, and not always correct:
model:GetExtentsSize().Y
or model:GetSizeExtents().Y
I forgot which it was and wiki on my phone gives me 403. Go look it up.
One of the two is a typo.
Thanks! I’ll check it out.
This is the correct one to use. It basically gets the size (Vector3) of the smallest bounding box it can make around all the parts of a model.
If you want to implement it yourself, you could do something like this (I’ve adapted a method that zeux mentioned on his website).
-- https://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/
local inf = math.huge
local abs = math.abs
local function getModelHeight(model)
local low, high = inf, -inf
for _, obj in next, model:GetDescendants() do
if obj:IsA("BasePart") then
local _, y, _, _, _, _, R10, R11, R12 = obj.CFrame:components()
local si = obj.Size
local ws = 0.5 * (abs(R10) * si.X + abs(R11) * si.Y + abs(R12) * si.Z)
if low > y - ws then low = y - ws end
if high < y + ws then high = y + ws end
end
end
return high - low
end
This grabs the minimum and maximum points in terms of Y coordinates of each part in the model (assumes they are block-shaped), and then finds the minimum and maximum of those, then returns the differences.
Usually I just measure my stuff manually by placing a part next to it and then resizing it until it matches, where I then look at the part’s size properties.