Raycast Precision Issue

image
Code: local function run() if not mouse.Hit then clearSel() return end params.Fi - Pastebin.com

Casting a ray along red line with a whitelist of the gray parts, such as the one I have selected in the above image. For some reason, that exact raycast will pick up the part I currently have selected.

Issue possibly has to do with the scale of the parts involved. For reference, that ray is a cylinder with a .001 stud diameter. Visually that distance is at most .005 studs. Does Roblox use poor precision in the ray casting math to optimize it for general use?

Before anyone says this, the issue is not something else. I can provide a rbxm to recreate if anyone needs.

Literally any advice at all here is helpful. Just praying atp im not going to have to implement my own raycasting system for more precise casts.

Recreation:
raycast_bug.rbxl (51.3 KB)

Have you considered the fact that the issue may be to do with the mouse hit position?

1 Like

I have. I just tried switching out mouse.hit with camera:ScreenPointToRay() - still same result. Furthermore, I have verified that the ray is actually on the red line and it is returning a result with instance == the selected part. So I am almost positive it is a bug with the raycast itself.

Perhaps it’s something to do with collisions?
image
enable this

1 Like

Nope, clear gap

Also, iirc raycasts aren’t collision based.

Raycasts are still dependent on the collision geometry of parts/meshes.

1 Like

Got it, I uploaded a file with the issue so you can see for yourself. It is really small so if the scale is the issue I wouldnt be suprised. Wish there was a parameter I could set in the raycast to be more precise though.

1 Like