I’m making a combat game, and I’m interested in whether or not raycast checks or spatial queries is more efficient at large scales for hitboxes. Has anyone already gotten an idea of this already?
I recommend using the following module for any melee weapons:
I’m aware of this one, just wondering if it’s better than just using GetPartBoundsInBox
every step
It depends on the use case, if it’s a melee weapon for which you need an accurate hitbox (hits only when the actual blade touches the opponent, for example) - you can use a raycast hitbox. Otherwise, a workspace:GetPartBoundsInBox()
will work just fine.
Spatial queries are much less efficient wrt performance when compared to raycasting. Spatial queries need to go through every possible part (though spatial queries are optimized likely using octrees or similar data structures) and determine whether or not the relevant condition is satisfied. You mention scalability here, the more possible parts that the engine has to consider, the more time the spatial query operation will take per call.
Raycasts on the other hand do not take more time with more potential parts, rather the time the call takes scales up with the length of the ray (if you are using raycasts for hitboxes, your ray will most likely be short, so the length will certainly not be a hindrance here). If you are looking for scalability, raycasts are definitely the way to go here.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.