Hello! One of those rare times once again when I ask a question. Today's question on my mind is how to properly calculate the height of an object. Your first instinct would probably be "Just read the Y size of the object", however that is not exactly the case. As shown in this picture: http://prntscr.com/gcn04x , the bold red object is "floating" in the air, and the space missing between it and the ground is represented by the translucent red object. The grey brick you see next to it is just for measure, and that measures 6.3 studs, (which is my definition of a proper height). The bold red object's proper height is 6.3 studs, however if I read the size, and position, the Y size is 4, and the Y position is 4.3. How am I to get the proper height which INCLUDES the translucent red part, which measures 2.3 to sum up to 6.3? (For future references, that bottom piece will not always be there.)
Another use for this answer is even when the object is FLAT on the ground! If you size an object, it's position is no longer 0,0,0. The position is based on the center of an object, which is not what I'm looking for! Any tips? Thanks
local actualHeight = part.Position.Y + part.Size.Y/2
Since the Position
of a part lies in its center, subtracting half of its height to that position will give you the position of the bottom surface of the part. That position is also the height of the gap between it and the floor.
All that's left is to add the part's own height:
part.Position.Y - part.Size.Y/2 + part.Size.Y
which simplifies down to part.Position.Y + part.Size.Y/2
.