Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Laggy projectile because of remote event?

Asked by 6 years ago

I have been using Remote Event to make a player spawn a projectile that moves forward by the help of body velocity. The only problem is that its laggy maybe cuz of server script generating it on client request. So, what's the best way or most efficient to do it so that it's lag free and FE compatible?

0
Look into NetworkOwner for projectiles. Nikkulaos 229 — 6y

1 answer

Log in to vote
1
Answered by
ozzyDrive 670 Moderation Voter
6 years ago

To give a smooth experience to the players, games often have the clients predict things. If everything had to be validated by the server and only then displayed to the clients, the client's input would first need to be sent over to the server which then processes it. The end result (such as a projectile object) would then need to be sent back to the client, which again takes time. The time it takes for a packet to be sent to another machine and then received back is called the Round Trip Time or latency.

Removing the visual stuttering caused by latency is fairly simple. Once the client notices new user input, it first checks if it can perform this very action -- it assumes it can do so. If so, it informs the server that it wants to perform the action and sends the necessary data over. The client then creates and animates the projectile itself. After the server receives the client's input and data, it first checks that the player is authorized to perform the action (such as has enough ammunition), then creates the server-sided projectile which cannot be seen by the clients. The server then performs the necessary collision detection using the server-sided projectile (the server-sided projectile is often just a ray, which leads to the projectile hitting the target immediately when the server receives the input).

To put it into a more compact form:

--[[
Client:
User presses mbutton1
    Check if possible to shoot
        Inform server
        Create client-side projectile
        Animate projectile

Server:
Receives client's input
    Check if possible to shoot
        Inform other clients about the projectile
        Create server-side projectile
        Animate projectile (if not using ray casting)

Other clients:
Receives the other client's input from server
    Create client-side projectile
    Animate projectile
]]

Client-side prediction is a must for a smooth online gaming experience. Here's a good read regarding the topic, and you can find many more over the internet.

0
I need to use this too I guess OBenjOne 190 — 6y
Ad

Answer this question