- Home /
The question is answered, right answer was accepted
Multiplayer Rotation is really slow
I'm working on a multiplayer shooter, and I have some problems with rotation.
Turning is handled internally completely normally, but it's rendered really weird to other players on the server, so that it slowly goes to the final position instead of syncing with the mouse movements of the player. This leads to bullets being shot in unpredictable locations depending on if the host or client is firing. I am really new to this, so I figure that there's a better way to handle rotation that what I'm doing, and I don't really understand how channels work, so I'm just going to embed my code and see what anybody can come up with.
PlayerCam
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
[NetworkSettings(channel = 0, sendInterval = 0f)]
public class PlayerCam : NetworkBehaviour
{
private float rotY = 0.0f;
private float rotX = 0.0f;
public float mouseSensitivity = 100.0f;
public float clampAngle = 80.0f;
// Use this for initialization
void Start()
{
Vector3 rot = transform.localRotation.eulerAngles;
rotY = rot.y;
rotX = rot.x;
}
void Update()
{
if (this.transform.parent.GetComponent<PlayerController>().isLocalPlayer)
{
float mouseY = Input.GetAxis("MouseY");
float mouseX = Input.GetAxis("MouseX");
rotX += mouseX * mouseSensitivity * Time.deltaTime;
rotY += -mouseY * mouseSensitivity * Time.deltaTime;
rotY = Mathf.Clamp(rotY, -clampAngle, clampAngle);
Quaternion localRotation = Quaternion.Euler(rotY, rotX, 0.0f);
transform.rotation = localRotation;
}
}
}
Answer by mcdemrer · Jul 25, 2017 at 04:53 PM
I fixed it by lowering the Network Send Interval within the Network Handler.
I have the same problem. What do you mean by "network handler"?
Follow this Question
Related Questions
Problem turning character on a sloped surface. 1 Answer
How to move as well as rotate the object to face the direction it is moving. 0 Answers
How do I make a vehicle turn properly? 1 Answer
Rotating Character 1 Answer
Rotate an object such that it is theta degrees relative to another object 1 Answer