As a Roblox developer, it is currently too hard to check if any BasePart is overlapping a certain position in the world.
The closest API we have to checking if a certain position is inside of an object is WorldRoot:GetPartBoundsInRadius()
. This API works well in most cases, but if your world includes any parts with a ‘Ball’ or ‘Cylinder’ shape, or you are using MeshParts with a CollisionFidelity other than Box, this API won’t work well. This is because in those cases the bounding box of the object is different from its collision geometry.
Use cases
A large use case for this API would be when programming projectiles. Projectiles are commonly used in shooter games, which is a very popular genre. When a player shoots a bullet it starts at a certain location. In the next frame the bullet has moved a certain distance and the game will raycast from the previous location of the bullet to the current location. On a raycast hit, the bullet is removed.
However, there may be some edge-cases when movable objects are involved. What happens when a player moves into the bullet in the time between the last raycast of the bullet’s trajectory and the next raycast? In that case the bullet would start inside of an object without having detected a hit on the previous frame, and so an additional check should be made to verify that the bullet does not start inside of an object before the next raycast takes place. If your bullets are represented with Parts you could use the WorldRoot:GetPartsInPart()
API. However it is very common for bullets to simply be represented with some data in code, such as a Vector3 representing the current location of the bullet and a formula describing the trajectory the bullet will take. In those cases you would have to create and/or reuse parts whenever a bullet is shot. Creating parts and moving them around with CFrame are - relatively speaking - very expensive operations and so should be avoided if you have a ton of active projectiles.
Another use-case for this API would be to create a camera effect when your camera is inside a certain volume, such as water, fog or some poisonous gas. Currently you would have to use a work-around similar to the previous example where you create a part, overlap its location with the camera’s CFrame and then call WorldRoot:GetPartsInPart()
. Parts cannot have a size of 0 however, so this work-around isn’t perfect. This work-around isn’t intuitive either and so an API for checking if a certain vector in inside of any collision geometry would be very helpful!