Help with spatial querying without using parts

im trying to detect if two sets of cframes and sizes collide by only using those two pieces of data and not using parts. how would i go about doing this? i also want to account for orientation

reason im doing this is ebcause i want to check if a lot of parts are overlapping without creating those parts just to throw away the parts

If one of the parts exist, you can do GetPartBoundsInBox: WorldRoot | Documentation - Roblox Creator Hub
I’m not sure how you would do it without either part existing, but I’m sure people smarter than me could answer that here.

yeah i want to do with no parts existing

Assuming the two parts are cuboids, I would first calculate the maximum distance each cuboid could reach from its respective center position (math.sqrt((Size.X^2 + Size.Y^2 + Size.Z^2) / 2)). Add those two distances and compare it to the distance between the center positions of each cuboid. If that is inconclusive, meaning the sum is less than the distance between the two cuboids, you could calculate the position of each vertex on one of the cuboid, and check if those positions are within the region defined by the other cuboid. If there are any, there is an overlap.

Note that the first part of comparing to the distance between two cuboids is not necessary, but recommended to have especially when there is a good chance the two cuboids are located in distant locations. It adds a shortcut for the algorithm, making it more efficient.

I found a page that explains this in more detail: geometry - Check if two rotated cuboids overlap? - Mathematics Stack Exchange. Using the lookvector, upvector, and rightvector, you should be able to use this exact method.

1 Like