I'm trying to implement a function where I detect the parts in front of a player that are within a set field of view. You can imagine it in a shape of a cone as seen in this image
I already succeeded in implementing a single line raycast to check the part in front of the player but I'm not sure how to do it in a widespread multi-part approach. The brute force approach would be to continuously cast from a minimum angle direction to a maximum angle direction but I think that's resource intensive considering this is done every time the mouse is clicked while a specific tool is equipped.
So is there any way to do this with Raycast or is there a more effective solution? Thanks in advance.
You could try to use https://developer.roblox.com/en-us/api-reference/function/Workspace/FindPartsInRegion3 but I think raycasting is more effective in your case.
The "brute force" approach may be too slow, but I'd recommend trying it anyway, especially if you can afford to have inaccuracies (by reducing the number of raycasts). Once you see how it performs, you can make modifications.
A more practical solution might be to go through all the parts that the player might have in front of them and determine if they're visible to the player (based on their angle compared to the player's camera). If the choice is between raycasting 1000x or checking the angle of 100 parts, if the performance isn't too costly, checking the parts may be faster (but you won't know until you try).