Approach 2: Server only RPC
The simplest working approach for networked games is to have the server handle the ability and then inform the client of the result. To do this, we will set up a
Server that executes the teleport code when triggered from the client.
Result: Works in networked games. However, there are a few problems with the way it works. There will be noticeable delay for the client using the ability, and the movement will
appear to be smoothed instead of being an instantaneous change of location.
First, there will be noticeable lag for the player using the ability, because the
command from the client needs to be sent from the server, executed there, and then sent back before the client knows that it has actually happened. Second, the smoothing code will
make the teleport feel like a smooth movement, where it should feel like an instant change of position. And third, the server's movement of the player will be perceived as a
correction, which is not the case and can mask real corrections when trying to debug the game's networked play.
Analysis: This works, but it's far from ideal. When the player presses the T key teleport, the command is sent to the server, but nothing happens locally. This can leave players
feeling like the controls are unresponsive, and the player will not immediately know whether the teleport command worked or not. When the server receives the command, it moves the
Character, but does not tell the client. On the next time the client sends an update, the server will see the client's reported location as being 10 meters off, and will send a
correction. The correction will cause the client to move (smoothly) to the server's expected location, effectively causing the teleport to succeed, although it wouldn't look right. If
we had set "p.NetShowCorrections" to 1, we would be notified of this as a network correction. In addition, if we want to polish the ability with things like particle or sound effects,
those effects will not show up correctly since the actual ability only runs on the server. Although the client knows when the ability is attempted (and the command is sent to the
server), there is no report of it succeeding or failing, just a correction that shows up shortly afterward.