Is magnitude too costly for a sword?

In my game, I am going to have 20 people in a server, some probably mobile users. Would it be too costly to use magnitude for a sword (each player having one)?

Assuming you’d want to use magnitude to determine whether or not to deal damage to a player, what you could do is run your magnitude checks client-sided, then fire a remote to the server, and have the server verify once using a magnitude check that the target player is within that distance, and if so, deal damage.

With minimal context, I can’t really see why you would want to use magnitude.

What else could I use? I have heard touched event being to laggy if too many events fire at once and raycasting is really slow.

I’ve never had any trouble using a touched event for a tool. If your tool isn’t very complex, and you’re only using a single .Touched connection, I don’t think you’d run into much trouble performance-wise at all.

Raycasting is not slow. It can be costly if used carelessly. However, ROBLOX can support a lot of raycasts before causing insane lag. It just depends on how you optimize it.

I’d recommend using a Region3 check. It creates a invisible bounding box within a certain region and acts like a raycast. You can whitelist objects to check against if you know what you’re looking for, which saves performance. It returns a table of all objects within a certain range.

Have the client execute the Region3 check, then have the server verify with a sanity check. (Distance from player to the hit object)

Magnitude checks would not be too costly but It will be inaccurate, if your making melee weapons your best option would be to raycast from a set of attachments on the sword, this module does that: Raycast Hitbox 4.01: For all your melee needs!. Btw the raycasting is not slow, it is only expensive when your casting long rays at a fast rate, however, raycasting a small ray every frame is very inexpensive.

So if I had a full server (20 people) on mobile (or a low-end device), and I had this module running on all their tools, would this run well?

Yes it will, for a game I’m working on with melee weapons on a server with 12 people it runs smoothly, and its the best solution for proper hit detection, and btw the computer i test the game on is trash because I want my game to run smoothly on all platforms.

2 Likes

A little confused on how it would be better to have the magnitude check on the client first, then have an event fired to have a “sanity” check on the server. I can’t wrap my head around it since wouldn’t that be more work than just checking it on the server in the first place? Not only could you avoid using the event, but you could also avoid checking it on the client. I must be understanding something wrong here. Maybe it has something to do with passing data or…? Please explain!

Nvm, was thinking about it last night and it totally makes sense. If you sent a table over, after doing a bulk amount of the work on the client, you could then only be checking to makes sure the client data isn’t false.