How do you boxcast with 100% accuracy?

I want it to work in the general case with meshes and unions as well (so you can’t just do box-box collisions and instead you will probably have to raycast)

I saw Boxcasting/Spherecasting Request but I have no idea how that works (nor if its actually accurate) & the code is kind of hard to read
Ideally the solution isn’t to just iterate in small increments and raycast

Right now I feel like the best solution is to make a part and use GetTouchingParts() on intervals of the boxcast (or the entire distance in one go) and sort the parts to get the first

1 Like

This model made by @AxisAngle allows you to cast boxes/spheres at arbitrary CFrames (not aligned to world axis like Region3)

For Members, you can see documentation of the model here:

(if not, PM Axis and see if he’ll move it to Community Resources where everyone can view it)

3 Likes

Oh man I should really rewrite that sometime. I’ll put it on my todo list.

1 Like

Not sure how that really helps me versus doing GetTouchingParts() because you still need to sort and I assume Roblox is more accurate

Swept volume casts would be good to build into the engine.
You have two options right now:

  1. Run your own collision checks on each part in the world (not possible for unions or meshes since you don’t have access to mesh geometry data)
  2. Spam raycasts

The latter is probably the fastest option for now since it’s taking advantage of internal physics acceleration structures.

6 Likes

I’d use GetTouchingParts for getting all parts that partially intersect with a box or sphere volume. It saves you implementation time and for me it hasn’t been computationally expensive enough to worry about it.

It doesn’t really fit your use case though reading through the thread, since you don’t just want to know which parts are in the volume, but also ordering of closest point in the volume to the source. So in that case, you’ll need box cast.

1 Like

Why is spamming raycasts better than GetTouchingParts?

GetTouchingParts works by tracking internal contact objects iirc; allocating and simulating contacts takes time and memory. The size of your swept shape is also beholden to part size limits.

2 Likes