Raycast Performance


So I wanted to run a local script that is casting rays everytime it loops to create an arcing grenade, my question is if this would cause any performance issues on the client because of the frequent looping of the rays?


According to Roblox staff, the overhead of raycasting comes more from the magnitude of your rays rather than the amount of them. I assume your grenade is not usually travelling a long distance, so it should be fine. Either way, in fact, it should be fine; computers can deal with more raycasting than you think. Many games cast multiple rays per frame per machine without any major issues.


Check out the Script Performance option in the “View” ribbon on Studio to find out about performance.

Anyways back to answering your question.
It depends on what you have inside the loop. Raycasting has its own effects, so you are bound to expect some type of decrease in performance. But it’s very minimal to my knowledge.


I don’t believe you’ll notice any performance issues with this. I’ve done much more without any issue. And you might as well try and see how it goes!


If possible I would use.

Note, this function benefits from internal optimisations that make it more performant than casting a ray for each cast point individually.


I think the real question to ask is whether or not you actually need a raycast for this, unless you’re being explicit in the instructions you want the code to follow. Either way; rays should not be detrimental for performance, especially noting that you’re handling them on the client. So long as your rays are not big, you should be completely fine.

Debug windows are always available to help you if you do see any noticeable performance drops.

1 Like