In my game, I’ve made a system that causes a player character’s head to turn as they turn their camera, this is done by modifying the C1 value of the character’s Neck joint Motor6D based on their current camera angle, done in a function bound to RenderStepped. I thought this would replicate since many actions done to a player character will replicate, but seeing as it doesn’t, I needed to implement a system that would allow this behavior to replicate to other clients, which would in turn require remotes as clients can’t directly access the CurrentCamera of other clients (to my knowledge, anyways).
The way I did this was have each client periodically send the CFrame of its CurrentCamera to the server through a RemoteEvent. The server then modifies a CFrameValue parented to the respective Player instance that tracks the CFrame reported by the client. Then, back on the client side, the RenderStepped function iterates through each Player, reads their CFrameValue, calculates what the C1 value of their character’s neck joint should be, and lerps it to that target angle for smooth turning.
Each client fires their RemoteEvent to the server roughly 20 times per second, and because I don’t quite have a full grasp on how much “stress” Luau can hold, so to speak, nor how taxing different types of calculations can be on performance, I was wondering if this rate was acceptable, too much, or if I can send the remotes even more often for smoother visuals. Only a single CFrame is passed each time the remote is fired, but I want to make sure I have a good idea of how much performance weight these things have for future reference.
Some side notes that may be relevant;
- Since this is a purely cosmetic effect non-integral to gameplay, the remote used is an UnreliableRemoteEvent.
- An event was used over a function so as to not have the server script yield while waiting for a client to return their CurrentCamera’s CFrame.
- The remote that controls the CFrameValues is only fired from the client to the server, never the other way around.
- There is a single remote all players fire to, and the server sided script that modifies the CFrameValues has a debounce for each player. I am unsure if this could cause problems and if each Player should use their own instanced remote instead, or if doing that would be unnecessarily complicating things.
- The only argument being passed through the remote (other than the Player whose client sent it, of course) is the CFrame of the workspace’s CurrentCamera.
- When determining neck joint C1 values on the client side, the information used to determine the local player’s neck joint is taken directly from their current camera rather than the CValue instance, since it can be accessed directly on their respective client. The CFrameValues are only read when determining the target C1s of other player characters.