The title, im making a volumetric projectile hitbox so i cant use things like .touched and i need to detect any number of entities at once, so no raycast.
Im wondering if running magnitude checks every heartbeat is reasonably performant to be used regularly in a game?
Magnitude Checking every heartbeat shouldn’t be a big issue with your performance, however it may depend on how many parts you are checking at a time, thousands of parts would likely cause lag, but otherwise no, It shouldn’t take that long to calulate and execute.
A Simple Benchmark test may help you determine whether it is performant or not, if it takes a long time, it may cause performance issues.
from my tests, it should take less than 1% of the Frame (Assuming you have 60 Frames per Second, and you arent checking too many objects)
You performance is always based on an n number of players.
Consider your performance implications as the max n players you can handle in the server. (Max Players)
You are magnitude checking (consider its max of 30), you are running calculations after EVERY frame after physics completion, which is usually 60 FPS. So you’re running 1800 (30*60) calculations per second.
I’d test it, and make sure to test it within an actual roblox game, not studio, as within studio, it hosts the server on your computer, so performance is dependent on your computer specifications, compared to a full game, where it is run on roblox servers.
If you’re worried about performance, you could use spatial partitioning so you’re not doing checks where they aren’t needed.
Here’s a resource I found, although it doesn’t support moving objects (like a player), but you could always find a better one or edit the module to fit your need:
If it’s a main mechanic of your game it’s perfectly fine to check magnitude on a loop, not complicated arithmetic, just check the position magnitude