Most efficient way to Raycast possible..?

I want to cast 100+ rays per frame. Now I understand there will be a performance hit doing this many rays, but they are only about 1 stud~ so it wouldn’t be that much of a hit.

Trying to make the functions into locals doesn’t seem to make that much of a difference either, like;

local ray = Ray.new
local FindRayPart = workspace.FindPartOnRay

Does anybody have any advice or methods regarding this…?

For the record, I fire hundreds of rays per step with no weird tricks and have no performance issues. Especially with rays with that small of a magnitude, you’re not going to have an issue.

4 Likes

What are you planning to do? maybe if you tell us we can figure out ways to reduce the amount of rays needed.

It’s not about reducing rays, I don’t need to. My main question is how to make them as efficient as possible.

Improving your algorithm (by reducing the rays cast, perhaps using a white/blacklist, or even reducing the length of the rays if appropriate) is the correct way to speed up your code.

Micro-optimisations like local variables are not going to make a significant difference because the bottleneck is the raycasting itself. This is why it would be helpful for you to give a higher-level explanation of what you’re trying to do.

7 Likes

I’m not trying to do anything, literally anything at all except cast 100+ rays per frame, more of an experiment. So reducing rays, or using whitelists and etc… don’t help in this situation.

My main question is still about and only, how to make rays as efficient as possible in a situation like this. I totally agree with what you are stating in any other type use-case though.

Your question is very vague. You can’t make rays any faster than they already are. Micro-optimizations are pointless, the only thing to make them faster is to do what sircfenner said,

1 Like

This is what I was asking, thank you.

1 Like