Smoothly Syncing Child Object Rotation in CCTV

Hi everyone, I could really use your help with an issue I've been struggling with for the past three days. I'm trying to create a new object inside a CCTV object that I can track in debug camera mode. This new object needs to have a network ID when spawned, which I managed to implement. However, the problem lies in tracking the information from the child objects of the CCTV, specifically CCTV_Pitch and CCTV_Yaw.

Currently, I’ve implemented this by updating the position and rotation through data sent from the server. When the data reaches the client, the new object instantly updates to the new position and rotation. However, I need this movement to be as smooth as the rotation of the main CCTV block, which rotates gradually rather than snapping instantly.

I don’t want to send new position data every 0.01 seconds, as this would put too much load on the server and still wouldn’t guarantee perfect smoothness. I believe the best solution would be to implement Lerp on the client side. I’m thinking of creating a custom component for the object when it’s spawned to handle this calculation locally, but I’m not sure how to approach it.

Could anyone guide me on how to achieve this? Any advice or suggestions would be greatly appreciated! Thanks in advance!

Other ideas that came to my mind:
1 - Create an object of type 'bone' in the CCTV prefab hierarchy that would inherit the position from the rotating CCTV camera block itself. These bones could be cycled through using the cyclebone command in the debug camera, similar to how it works with animal or player bones, but I also don't know how to create exactly this type of object.
2 - Change the Debug Camera's attachment point to the CCTV. By default, this point is located at the camera's wall mount - CCTVArm, but it could be moved to the rotating part of the camera, which I also don't know how to do.

Look at the cctv code how the server is handeling the rotation also it will require you to SendNetworkUpdate(); for the client to know its position

ngsWWCTeML56SVK.png Razor

Look at the cctv code how the server is handeling the rotation also it will require you to SendNetworkUpdate(); for the client to know its position

            private void UpdateSwitchTransform()
            {
                if (_switch == null || _switch.IsDestroyed || _cctv == null || _cctv.IsDestroyed)
                {
                    Cleanup();
                    return;
                }

                var cctvPitch = _cctv.pitch;
                if (cctvPitch == null)
                    return;

                try
                {
                    _switch.transform.position = cctvPitch.transform.TransformPoint(_config.SwitchOffset);
                    
                    Quaternion targetRotation = cctvPitch.transform.rotation * Quaternion.Euler(_config.SwitchRotationOffset);
                    
                    _currentRotation = Quaternion.Lerp(_currentRotation, targetRotation, Time.deltaTime * 5f);
                    _switch.transform.rotation = _currentRotation;
                    
                    _switch.SendNetworkUpdate();
                }
                catch (Exception ex)
                {
                    _plugin.PrintError($"Error in UpdateSwitchTransform: {ex.Message}");
                    Cleanup();
                }
            }​

Thanks for the answer, but I can't figure out where to find the information, please give me a link to this information.

I also attached examples of how I have implemented this functionality at the moment, but unfortunately it works intermittently, although FPS and Ping are Ideal

Video 1 - https://drive.google.com/file/d/1VJ4GlPu4VyYTXEW3yZ0qfF5yPqE_7IZO

Video 2 - https://drive.google.com/file/d/1zYi9pXiraXlrvMXBn2yXhMCQfBYTKBIk

 

You must decompile the server dll files most in in the asembly-csharp.dll

jiXJYmbEhMxG049.png Razor

You must decompile the server dll files most in in the asembly-csharp.dll

I used ILSpy and studied a lot of information, but I'm still a beginner and not entirely sure what's relevant here. I found code in CCTV_RC that uses Lerp to update positions, replicated the same approach exactly, but it didn’t produce any results.

	public void UpdateRotation(float delta)
	{
		Quaternion val = Quaternion.Euler(pitchAmount, 0f, 0f);
		Quaternion val2 = Quaternion.Euler(0f, yawAmount, 0f);
		float num = ((base.isServer && !base.IsBeingControlled) ? serverLerpSpeed : clientLerpSpeed);
		((Component)pitch).transform.localRotation = Mathx.Lerp(((Component)pitch).transform.localRotation, val, num, delta);
		((Component)yaw).transform.localRotation = Mathx.Lerp(((Component)yaw).transform.localRotation, val2, num, delta);
		if (fovScales != null && fovScales.Length != 0)
		{
			if (fovScales.Length > 1)
			{
				fovScaleLerped = Mathx.Lerp(fovScaleLerped, fovScales[fovScaleIndex], zoomLerpSpeed, delta);
			}
			else
			{
				fovScaleLerped = fovScales[0];
			}
		}
		else
		{
			fovScaleLerped = 1f;
		}
	}