- Home /
The question is answered, right answer was accepted
Network rotation is laggy and slow
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.
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
[NetworkSettings(channel = 0, sendInterval = 0f)]
public class mouseLook : NetworkBehaviour {
public float lookSensitivity = 5;
public float yRotation;
public float xRotation;
public float currentYRotation;
public float currentXRotation;
public float yRotationV = 0.0f;
public float xRotationV = 0.0f;
public float lookSmoothDamp = 0.05f;
public GameObject gun;
void Update() {
yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
xRotation = Mathf.Clamp(xRotation, -90, 90);
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, ref xRotationV, lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, ref yRotationV, lookSmoothDamp);
transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
gun.transform.localEulerAngles = new Vector3(0, 90, 90);
}
}
Thanks in advance.
Answer by www4 · Jan 16, 2018 at 05:27 PM
Fixed it by changing the interpolate rotation factor on the network transform to 0 and checking the "sync angular velocity" box.
Answer by Diukrone · Jan 16, 2018 at 12:47 AM
Change your Update to FixedUpdate! All Vector3 and Quaternions calculations should be done in FixedUpdate().
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
How to sync non-player objects movement in multiplayer game? 0 Answers
UNET Clients spawn Childs on Player & Client Sync problems. 0 Answers
Network Transform Slow Rotations 0 Answers
Multiplayer problem: How can i figure out client lag in position updating calculated by the host? 0 Answers