Is it reasonable to run magnitude checks on heartbeat?

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)

It’ll be fine. Try it and see. There are other possibly faster ways (e.g. comparing the square of magnitudes, octrees) but magnitude will be fine.

1 Like

Do you know if it checking through a folder of all character models for the HRP would cause any issues?

Well consider this.

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:

wouldn’t this kinda be obsolete with StreamingEnabled?

I’m pretty sure that’s not related to this

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

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.