Controlling a custom character with no client side lag

Hi,

I’m trying to create a custom character (dragon) that when the player jumps on their back, they can control it via where their camera is pointed and using WASD. I want instant feedback for the player controlling the character.

I’ve looked at https://developer.roblox.com/articles/Network-Ownership, I know I’d need to control the character from the players client and give that player network ownership of the character model.

The issue is, as the character will be controlled on the client it would be possible to exploit i.e. teleport the dragon, increase it’s speed massively, play the incorrect animations even with FE. What would be the best way to do this? Any help would be greatly appreciated.

Cheers!
Integern

This is a pretty common question, which I’ve personally answered versions of in a couple threads. Here are some of my responses. However, If you feel that they aren’t really applicable, I’d be happy to put in some extra thought to consider your special circumstances.


3 Likes

Those were really useful thank you! A couple queries if that’s ok… (only thing I’ve done similar to this is sending the client action to the server, then the server doing everything and so lagged on the client)

For clarification, if the player moved the dragon to the left the client would visually replicate this movement immediately, then it would actually get moved on the server? My question is if the player moves say 10 studs in the time it takes to tell the server to move it 5, what’s stopping the client then seeing being teleported back 5 studs and moving the other 5 studs again? (I believe you did explain this but still confused me after reading through a couple times apologies!)

Haha, no sane programmer likes dealing with latency in an authoritative server model. It is one of the infamous problems of game development. It is responsible for so many hacks, both by developers and exploiters.

Yes, the client plays the movement immediately. If the client tells the server to only move 5 studs, then the client shouldn’t move 10, but stop when it reaches 5 studs. Generally, the client should send player input to the server, like “w was pressed”, which tells the server which direction to move in rather than a specific distance. The client just moves slower in that direction until the server sends the official update to all clients. This can be hidden as a speeding up in a direction, since instantaneous velocity changes are not realistic anyways. The update from the server contains the server state (like the position), the action (like direction and velocity to move), and a timestamp (so clients know exactly where the server is even after a long transfer period on the wire).

Now, sometimes as you hinted at, the client will underestimate or overestimate the latency, meaning that the interpolated position is a bit off from what the server says it should be. This is unfortunate and there is no fix for it. Lag spikes are very bad, with client ownership, server ownership, and every other model. Game developers can’t do anything to fix this short of wiring their servers directly to their players’ houses. However, game developers can do their best to hide it. How you hide this position discrepancy is up to you, but usually tweening to the correct position is the best method. I’ve played games that use teleportation, and I’d really prefer that they didn’t. The visual effect of being transported is jarring. I’d really like them to lie to my face and just tween the positions. :smiley:

7 Likes

Thank you! Really appreciate it :slight_smile: