So let’s say you have your average combat game. You detect when the punch tool is clicked through an event obviously, now for hit detection.
I wouldn’t use spatial queries as they hog more resources, a Touched event would have bad detection. So I’m between raycasting/magnitude. I believe magnitude would work the best as raycasting would take up more resources right?
Or am I wrong, not sure. Either way I think the difference would probably be very small, but please tell me.
Magnitude (distance) checks could be more performance intensive when used in mass. I would suggest using spatial queries as they are more practical in this scenario, and they have more functionality.
Magnitude is just calculation with the most expensive part is calculating square root. So it is not as intensive as raycasting and spatial queries, which both require a lot of config and moving part to factor in.
Still if you want to distance checking. I recommend using fast Distance checking algorithm which does not require calculating square root.
for punch and close range abilities I use a combination of raycasts and magnitude checks. So raycast from the players mouse to the target they want to punch and then magnitude check if they are in distance on the client and then again on the server.
Im asking that because magnitude checks will always be more performant compared to raycasting or spatial querying, if there is only 1 rig being queried. There would realistically be more like 50 rigs, therefore making a more accurate benchmark.
But aren’t punch tools usually just about how close you are to the other player?? I’m not sure why you’d need to raycast to the player’s mouse and the target.
Well, if you make the distance for getting punched like 2 studs. I don’t think those issues would really arise. Since you’d be quite close to the player (that you want to hit), of course on the player’s screen they will feel like they’re miles away, however technically speaking it would work as intended. And I don’t think we can really fix that due to ping.
It’s easier to do it the way I described, because your method involves using a magnitude check on EVERY player in the game until you find one that is closest to you and apply damage. What if you want to punch player A, but player B is closer and it punches the wrong person?
Yeah I guess, but I mean I don’t think it really makes much of a difference to be honest so I think I know which one to do now. Although raycasting may be better to stop a player from getting punched through a wall.