Which one is heavier magnitude or raycasting

Im making a system and I got a problem that i can use magnitude or raycasting to solve it, but im wondering which one is the best in performance stats

Depends on what you mean. If you know what you are checking (like it’s just 2 parts) magnitude will certainly be faster. If you are comparing everything though, raycasting will use some techniques under the hood to remove things from testing that it can’t possibly collide with, reducing the amount of things that would need to be checked.

Ultilimately you would need to benchmark to know for sure, but if you are only checking a small amount of things magnitude is probably faster. If you are testing a lot of things, raycasting will probably be faster

1 Like

The only time I’ve found raycasting to be slow is when trying to cast multiple times on each heartbeat on 20+ NPC vehicles (for collision detection) simultaneously. I had to tune it down to just one raycast per interval to make it acceptable.