Fastcast lag compensation

image

Hey, im looking to fix my client to server delay.

When the client shoots a weapon in hits perfectly, but during the time it takes for the client to send relevant information to the server, and then have it to fire the player couldve moved and so the problem. (refer to diagram if still confused)

a friend of mine has suggested to cast a ray on both the client and server, then (assuming the client has hit an object) utilize the ClosestPoint function to check if the magnitude of both rays is within acceptable levels, and then if that returns true deal damage.

However im using fastcast and im not sure if the closestpoint function is compatible as fastcast has its own ray constructor functions rather than using ray.new explicitly.

local serverCompare = (serverNew.Unit:ClosestPoint(Part.Position))
local clientCompare = (clientNew.Unit:ClosestPoint(Part.Position))
            
if (serverCompare - clientCompare).magnitude < 10 then
(deal damage)

Any help on this issue would be appreciated, I am willing to post code if it is needed.

2 Likes

You could disable their movement while firing, maybe?

2 Likes

Why would i even consider this

5 Likes

You have a pretty good point lol

4 Likes

i appreciate you trying to help but its just not a viable solution at all, cheers regardless

1 Like

ok then make your own raycasting module

1 Like

No thanks, Id like to use fastcast and im not very good at programming physics stuff like fastcast has. Please comment something insightful/ answer the question next time.

4 Likes

You said your not sure if its compatible, I suggested you make your own module

1 Like

And im saying that it is out of the question for a plethora of reasons i wont get into right now for the sake of both our sanity.

Anyone else? Really need to get some assistance on this ASAP.

1 Like

It would probably be of more help if you added the code you actually having trouble with

no code im having trouble with specifically, the goal of the post was to ask what methods i should use to achieve lag compensation. (with fastcast)

still looking for help with this.

On the server, keep a track of the locations of all the players at a fixed interval and the ping times of all players. When a projectile is hits a player on the client, have the client fire a remote to the server to indicate that it has happened. Then, on the server, you will need to make fake clones of all the players and interpolate the positions of them all based on the ping time of the client which fired the remote and the positions which you have been tracking. See if the ray actually hit the player by shooting one at the fake players

I did actually start creating something like this.
https://gyazo.com/4e8626fccbf3d41d420a49cc9d53363d?token=530ada580a4b88a397acbd5e18197e3b

interpolate the positions of them all based on the ping time of the client which fired the remote and the positions which you have been tracking

Could you clarify what you mean by this? Would i take the clients ping and use that see what character appeared on their screen at the time, then checking if the ray hit said character?

Yes, that was what I was trying to convey.

how would i achieve this though? fastcast uses an onhit event so it doesnt make sense to me how i could check if the ray wouldve hit something

like, would i have to move the character back and then do a magnitude check? how would i use the players ping to achieve this? if its magnitude how to i do that with fastcast?

The lag shown in your image seems to be a lot, I don’t use FastCast and I don’t know is your image even accurately reflecting the lag. Regardless, @/IProgramForFun is correct, make your own raycast module which you can have a better insight on how everything works. It is not necessary to be very complicated, my own raycast modules only consist of less than 500 lines. (I think)

There’s definitely a delay between client and server raycasting, instead of checking 2 different positions between client and server, I suggest that you should just compare the time taken for the remote to fired. Such as if it takes over 2 seconds for the server to receive the remote signal since the client fires it, decline the shot.

dont have the time/ experience to create my own raycast module and denying the players shot just because the servers have messed up leaves the player confused and annoyed, again these are simply not considerable options and id much rather take the time to create a lag compensation system like @UntitledProtocol suggested.

1 Like

If anyone else is still having this issue, the best scenario is to fire a ray on the client, and send over the Instance and the RaycastPosition of the FastCast Ray and compare their magnitudes, if the distance between the two is less than ten, its likely that the shot should hit.

If you really want to keep exploiters away, you could also fire a ray on the server, and if the points between the client and server ray are too far then invalidate the shot.