Replicate a variable/property client->server
I started experimenting with multiplayer for my project just yesterday and it's impressive how many things work "out of the box". What I am trying to do now should be pretty simple too, but I'm not sure how to do it.
I just want clients to constantly send a direction-vector to the server that represents the mouse-cursor-direction in world-space. I think there is no way the server can do this by itself, because (afaik) it can't know the position of a client's cursor, and even if it did, it would also need to know the client's viewport settings to make any use of it. So I want the client to have "authority" over this vector and it should be treated like any other "input" from the player controller.
The only way I can think of atm would be to write a server-function and call it from the client with the direction-value, only to set the property on the server. I would have to call that function every frame though and I suspect there is a better way to simply replicate a value from client to server. Any help?
Nope, rapidly calling an RPC to send to the server is the way to do it! You can call it less frequently than every frame if you want. Since it's a cosmetic value (at least, I'm assuming it's cosmetic, and not something used for authoritative decisions) I'd recommend calling it less frequently (maybe 10 times a second?) and using a smoothing/interpolation on clients (every frame) so that the value changing doesn't look jittery.
Follow this question
Once you sign in you will be able to subscribe for any updates here