Network rotation is slow and laggy

Updated on January 16, 2018 in [A] Multiplayer
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on January 16, 2018

I’m working on a multiplayer FPS. I have a weird problem with player rotation. Locally, rotation is controlled without any problems, but it’s projected really odd to other players on the server – when a player rotates quickly, other players see his gameobject going slowly to his final position instead of syncing with player’s mouse movements. I don’t believe it’s a scrypting issue, but here it is anyway.

 

  1. using UnityEngine;
  2. using UnityEngine.Networking;
  3. using System.Collections;
  4. [NetworkSettings(channel = 0, sendInterval = 0f)]
  5. public class mouseLook : NetworkBehaviour {
  6. public float lookSensitivity = 5;
  7. public float yRotation;
  8. public float xRotation;
  9. public float currentYRotation;
  10. public float currentXRotation;
  11. public float yRotationV = 0.0f;
  12. public float xRotationV = 0.0f;
  13. public float lookSmoothDamp = 0.05f;
  14. public GameObject gun;
  15. void FixedUpdate() {
  16. yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
  17. xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
  18. xRotation = Mathf.Clamp(xRotation, -90, 90);
  19. currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, ref xRotationV, lookSmoothDamp);
  20. currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, ref yRotationV, lookSmoothDamp);
  21. transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
  22. gun.transform.localEulerAngles = new Vector3(0, 90, 90);
  23. }
  24. }

Thanks in advance.

  • Liked by
Reply