Hello!
Well technically your solution works, but as you said can be terrible for networking…
I try to explain some techniques which may help you…
Network only inputs and simulate on clients:
Technically this technique as his name show super easy, but not really synced mechanism.
What you need do just network input and let client simulate “lean”.
If player start lean left right (or in whatever direction) you just replicate that input and start lean left / right (whatever) on other clients… Simply just play your timeline.
If player ends lean, send input to other clients to stop at desired lean…
Perhaps this may cause some “desync”, so when this simple system is done you can start iterate and implement further techniques like:
Server validation:
Once lean ends you can multicast actual lean value to validate clients lean value… if you have mismatch between values you can interpolate to that value, so every client will be mostly in sync.
Smoothing / Client predicting:
This technique also built on input (mostly used for movement) or movement values like velocity, torque etc.
In short this technique try to predict “movement” on client based on server validated values…
like client send wohoo im moving with 0,0,1 velocity - server check client can move and update his location - forwarding to other clients wohoo this actor was moved - other clients start movement - client send info again wohoo in this frame i moving with same value - server checks / forwards info - other clients continue simulating and check incomming locations of course…
then trouble comes… client lagging and not sending any info to the server in the next frame. server cant update other clients… what happens now?
other clients still simulate movement and predicting… when client can send info again server and other clients will check there was mismatch on the movement or predicting path was good… if not we correcting.
So technically clients just smoothing / predicting movement between two updates if he can and continue movement if no updates there but the last command was “move forward or we have velocity(0,0,1)”
Of course ton of other techniques exist, take a look and google about networked movement… im sure will help.
In your case i think simpliest if you add a replicated float to your character as “lean value” use some onrep functions and whenever your character is do lean, send server rpc to update server value…
server then will update lean value to other clients and with onrep you can lerp or interpolate between old and new values…
Yes some delay will be there, but honestly… we talking about multiplayer game… there will be always a delay… no network exist which can work without delay ;D even LAN sometimes have some small (1-2ms) delay…
So try to make friendship with the delay, because if not … that will be your worst nightmare in your multiplayer game