Replicate Motor6D

Any efficient way to replicate the Motor6D in the character for torso/head movement efficiently? Currently I fire a remote event every few frames when mouse movement is done and then lerp the Motor6D in a server script. Anything more efficient?

2 Likes

You can just change it locally and the part positions will replicate

1 Like

They don’t.

3 Likes

I do a similiar thing, pinging the server occasionally and having the server collect everyone’s values, then distribute a table of everyone’s values to all clients on a regular interval. Each client interpolates and renders the motors clientside.

It’s a good idea to see if you can find ways to minimize the amount of information you’re sending. For example, say my head looking system modifies the shoulders, waist, and neck (four motors) based on where the camera is pointed. I could calculate all those motor values on the client and send it off to the server and have the server send those values back to the clients. This would be four CFrame matrices per client, which could add up. You’d be moving much less information (only an x y z for each client) if you only distribute the camera look vector and have the clients each calculate the motor positions in separately.

I don’t know what the difference is between making optimizations like this and not. It might not be appreciable. Ultimately, it’s easiest and fastest not to worry about efficiencies like this until you know they’re causing you problems.

9 Likes

To reiterate:
I agree not having to worry too much about optimizing very early however its important to stress the that is a very good idea to limit the amount of noise on the network as much as possible, especially for values that refresh consistently. Bandwidth is very expensive.
Opting to send a single look vector rather than three or four CFrame coordinates is exactly the step one would expect when considering network limitations.


You could also just send the pitch and yaw of the look direction as an array if you dont care about the roll if you really want to squeeze some space but a lookvector is honestly good enough.

5 Likes

– Client
[Remote]:FireServer([Head].Neck.C1:ToEulerAnglesXYZ())

– Server
Remotes.Global.OnServerEvent:Connect(function(…)
local Args = {…};
local Cliente = Args[1];

if Cliente.Character ~= nil then
	local Head = Cliente.Character:FindFirstChild('Head');
	if Head then
		local Neck = Torso:FindFirstChild('Neck');
		if Neck then
			local CFrameN = Neck.C1*CFrame.Angles(Args[2], Args[3], 0);
			Neck.C0 = CFrameN;
		end
	end
end

end)

Take the angles of the CFrame of Part1 of Neck and then send only numbers to the server, you decide whether to send it to all the players or that the server does it, it would be your decision, in this case, the server does it to not do so much work

1 Like

It’s generally not a good idea to let the server handle any kind of rendering, moreover, this method is very hacky and results in undesired behavior where the original client is sent back the C1 by auto replication from the server, causing the property to constantly switch between client and server values.

Edit: Oh wow, I did not realize this was a necropost.

1 Like