Answered by
XAXA 1569
7 years ago Edited 7 years ago
01 | function GetModelAABB(model) |
04 | for _, v in pairs (model:GetChildren()) do |
05 | if v:IsA( "BasePart" ) then |
08 | local baseCf = cf * CFrame.new(-size/ 2 ) |
12 | local testCorner = (baseCf * CFrame.new( size * Vector 3. new(x, y, z))).p |
22 | modelMin = Vector 3. new( |
23 | math.min(modelMin.x, testCorner.x), |
24 | math.min(modelMin.y, testCorner.y), |
25 | math.min(modelMin.z, testCorner.z) |
27 | modelMax = Vector 3. new( |
28 | math.max(modelMax.x, testCorner.x), |
29 | math.max(modelMax.y, testCorner.y), |
30 | math.max(modelMax.z, testCorner.z) |
38 | return Region 3. new(modelMin, modelMax) |
This returns a Region3 that hugs the model.
Get each corner of each part in the model, and get the minimum/maximum in each dimension. Return a Region3
made out of these. I have not run this, but in theory this should work. Make sure model
is actually a model, otherwise this will error.
EDIT: Also, parts are not examined recursively. You may want to modify this so that it does.
EDITEDIT: Tested and found a missing parenthesis. It works.