How would find the distance between a parts top and bottom.
Unlike finding the distance between two several parts. I’m only trying to find the distance between a parts top and bottom. I haven’t tried any solutions yet because I don’t think there currently is a method of finding the distance between a part’s top and bottom.
What if you made two points and just added/subtracted the part’s size to it?
local top = part.Position + Vector3.new(0, part.Size.Y/2, 0)
local bottom = part.Position - Vector3.new(0, part.Size.Y/2, 0)
local dist = (top - bottom).Magnitude
Just an idea, but this might work:
math.abs(part1.Position.Y - part2.Position.Y)
Please read my first post carefully. To keep it simple I’m only using one part.
when you say the distance from the top to the bottom, do you just mean the size of the part’s Y?
Could you explain this in a more informative way?
if the part’s orientation is 0,0,0 then the part.Size.Y is the distance from the top of it to the bottom of it
This works but only when the part is completely not rotated
You could try this script that gets the cframe positions of the top and bottom faces using the part’s size’s Y component
function FindDistBetweenTopAndBottom(Target: BasePart)
local Top = Target.CFrame:ToWorldSpace(CFrame.new(0,Target.Size.Y/2,0)).Position
local Bottom = Target.CFrame:ToWorldSpace(CFrame.new(0,-Target.Size.Y/2,0)).Position
return (Top - Bottom).Magnitude
end
You can also use this function to get distance between left/right front/back faces by using x or z components
This is equivalent to Part.Size.Y
. You just added half of Size.Y to itself Size.Y/2 + Size.Y/2
which is equal to Size.Y.
There may be a better way to do this, but this is my solution. This function returns a Vector3 size. In your case, you would index the Y value to only get the height.
This is for only one part.
local function GetBoxSize(Part: BasePart): Vector3
local model = Instance.new("Model")
local clone = Instance.new("Part",model)
clone.Size = Part.Size
clone.CFrame = Part.CFrame
model.WorldPivot = CFrame.identity
return select(2,model:GetBoundingBox())
end
This is for multiple parts
local function GetBoxSize(Parts: {BasePart}): Vector3
local model = Instance.new("Model")
for _, v in ipairs(Parts) do
local clone = Instance.new("Part",model)
clone.Size = v.Size
clone.CFrame = v.CFrame
end
model.WorldPivot = CFrame.identity
return select(2,model:GetBoundingBox())
end
This reply is the equivalent of finding the parts size, which could be simply be done by doing:
local size = p.Size
All this is currently doing is finding the the parts y axis.
S = parts.Size.Y/2 is distance from center so pretty much you do (top = part.Position.Y +S) (bottom = part.Position.Y -S)
I don’t think you know how this works.
- First of all, it takes all parts into a model
- Then it sets the model’s world pivot to
CFrame.identity
(Zero rotation, and Zero position) - Then it takes its Bounding Box (CFrame Pos, Vector3 Size)
Clearly you haven’t tested my script, because I did, and I know that it works. It takes the size of a part in global rotation.
If you don’t know about pivot, you can search about it. If you don’t know about CFrame, you can search about it. If you don’t know about the Bounding Box, it is just the size of a model.
And also, about the solution and the problem, the solution was taking the position of the parts top and bottom. But in your post you said “distance between top and bottom” which is equal to Part.Size.Y
.
You’re coming off as quite rude. The only thing is script does is fine the parts y. And I have tested that piece of waste you call code. I usually don’t get frustrated about some dude criticizing my profession, and skills. The only reason I selected him as the solution was because every single post has been the same, including yours, the only difference was that you made it more complicated than it had to be. I’m sincerely sorry if this comes off as rude. .
I’m sorry if I was rude aswell. I understand what you are saying. Its just that I hate when people judge code without testing it first. I thought you did not test it so I got irritated, thus what I said was also affected.
I tested this, and I got close results. If it did not work for you, I will just post screenshots of me doing it and my code working.
You wanted a different solution anyways (and I misunderstood your problem) so let’s not argue about my code not working.
I never so your code didn’t work. And I’m personally sorry, if this offended you in way.