How to detect a hit with a Server to Client Raycast

I have a NPC which fires a Projectile. The server fires a raycast. I am using Fastcast.

The issue is replicating this projectile.

If I fire the Server Raycast and then a FireAll, the Client Raycast sometimes will hit and the Server Raycast will not, visa versa.

Should I just detect the hit based on the Server Raycast and then if it hits, fire to the client and make it so the visual projectile would 100% hit on the Client side (will most likely tween it)

Or is there any other way to do it?

I also use Fastcast.

It depends on what you’re doing and how much trust you want to give to your players. Keep in mind that the server-side and client-side bullets have pretty much the exact same trajectory. It’s not like the bullets are tricking you with and going a different direction on the client than on the server.

What you’re doing is fine. Your players will simply learn to avoid the trajectory and assume the entire projectile path is “hot”, where standing under it could get you hit at any time.

You can alternatively fire the projectiles and let the clients themselves decide whether they were hit or not. This is good on pure PVE games where dodging is very important. The drawback is that exploiters could simply not report any hits back to the server. These days exploiters are rare, though.

Ah I gotcha, yes dodging would be very important so I may try the Client one.

Although if there were a way to aline both the Server and Client shot it would benefit heavily. By chance do you have any ideas that may work for that?

It’s impossible to perfectly align the bullets. This is a commonly studied problem in computer synchronization and data transmission. The client bullet will always be at most x ms behind the server side (x is the player’s ping).

The best you can do is guess/estimate.

local function GetBulletCFrame(t)
-- returns the current position and rotation of the bullet given the time elapsed since the bullet was fired

Instead of letting the client start at t = 0 for the bullet position, you can assume some time has passed for the packet to send and arrive at the client. This time is half the ping (remember, ping is a round trip time)
local lateT = 0 + ping / 2
local startingCFrame = GetBulletPosition(lateT)
– spawn bullet at startingCFrame and move it

Because you’re guessing, it maybe cause some unwanted side effects (for example, a passing car blocks the bullet, but the client is guessing that the bullet is still travelling so it shows it phasing through the car on the client).

I would still recommend the client-sided or the server-sided hitbox setups.

Okay i gotcha, thank you very much for your response!

Ill tryout the client setup and try and implement some measures to prevent any exploitation going on with them.

i cant help with that, the material is undiscernible

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.