Hello Everyone, I am making a shooting game and its time to add the actual hit detection. My method is to shoot a ray from the client, and another one from the server via a remote event that connects both (the client fires the event). This works really well, but with automatic guns such as miniguns that have a really high fire rate, i suppose it would be very lag since many remote events would have to be fired for each player.
From experience i know that roblox doesn’t handle well remote events fried at a big rate constantly.
Is there another secure but accurate method to detect hits that other fps games use that i am not aware of, since if i just try server raycasting, its very inaccurate cuz of ping
Maybe you could fire the raycast on the server only when the client thinks it hit an enemy? This way you can still do sanity checks on the server, but only when strictly necessary
I think you are underestimating the amount of networking roblox can actually take. For example, relaying the LookVector for every single player in the game, there is no “optimal” way to actually relay that information, you just need to use an Unreliable Remote event. For bullet detection I would recommend just doing 2 raycast, one on the client which would be used for processing vfx, etc. Another one on the server. If you do send some data back, ensure it has nothing to do with the actual raycast, but rather the effects of the raycast. Therefore you are not wasting bandwidth, since you already computed that raycast on the client.
Is this hitscan? Or a simulated raycast? Either way, don’t be super complex about it, just make it. If it’s an issue later on revise your code and go from there. A lot of programmers get caught up on this perfection mess.
But to answer your question, you’ll want to look at ratelimiting on the client. Which is essentially just allowing an x amount of network events to happen in y time. You can set this up to work with guns, so that someone can’t actually spam the trigger button, or break it then cause a lot of lag.
If you’re doing a simulated projectile, you’ll want to look at simulating the projectile in increments of time, rather than simulating the projectile every single server frame. You can squeeze some performance in there, but you’ll lose overall raycast precision, but that’s the trade.
For hitscan, don’t worry about it. Just go with a ratelimiting system of sorts.
If you want to know how exactly “rate limiting” works just ping me. You already do this when designing gun systems without really knowing it.
The idea is that it just doesn’t even fire to the server when the client’s raycast fails to hit an enemy. Not an ideal solution if you need to have an impact effect where the bullet hits, but can be used alongside that need for something that fires VERY quickly like a minigun (30+ shots per second) for a long period of time.
A small trick you can do to reduce server load is to not always replicate the bullets fired from automatic weapons to other clients. It’s not going to make a big difference to an enemy if they see an assault rifle only fire 75% of it’s bullets (with some exceptions like the first bullet always being visible).