Client replicate Motor6D offset to server

Oh I had the exact same issue with my mech’s turret system. The fix is actually quite simple though it may be quite a hack. I locally cloned the Motor6D and disabled the server one to avoid the conflict.

function TurretController:EnableLocalControl()
	if self.LookAtConnection then
		self.LookAtConnection:Disconnect()
	end

	if not self.LocalControl then
		self.ServerJointMotor6D = self.JointMotor6D
		local originalTurretMotor = self.JointMotor6D
		originalTurretMotor.Enabled = false
		local turretMotorClone = self.JointMotor6D:Clone()
		turretMotorClone.Enabled = true
		turretMotorClone.Parent = originalTurretMotor.Parent
		self.JointMotor6D = turretMotorClone
		self.LocalControl = true
	else
		--warn("Local control already enabled")
	end
end

function TurretController:DisableLocalControl()
	if 	self.LocalControl then
		self.JointMotor6D:Destroy()
		self.ServerJointMotor6D.Enabled = true
		self.JointMotor6D = self.ServerJointMotor6D
		self.LocalControl = false
	else
		warn("Local control already disabled")
	end
end
--send the correct Motor6D to be tweened, and the current local jointMotor6D C0
function TurretController:GetLocalC0Orientation()
	if self.ServerJointMotor6D and self.LocalControl then
		return self.ServerJointMotor6D, self.JointMotor6D.C0:ToOrientation()
	end
end

Edit: If you are confused if self and tables you can replace it with local variables like the below code

No self here just variables to store the motor6D instances
--in the client script
local neckJoint : Motor6D = --path to neck joint in character
local serverNeckJoint = neckJoint --store it in another variable
serverNeckJoint .Enabled = false -- disable the server neck joint
neckJoint = neckJoint:Clone() -- clone it locally
neckJoint .Enabled = true -- enable it
neckJoint.Parent = serverNeckJoint .Parent -- reparent it

Also here is a better video showcasing the issue for anyone else watching, incoming replication lag is set to 0.5 to really show the client-server delay causing the “jitter”.

12 Likes