Hi Unity,
I’m having issues with rapidly flickering lights when I run my client on a network.
I have a day/night cycle by using a yellow light and a blue light that rotate around the plane with a simple rotate script.(moon and sun). However, when the client runs it, because it’s being updated constantly with my position/rotation update script and network view, the lights flicker a few times every second. I’m guessing this is because there’s a constant update of the position of it, but why is this happening? How can I fix this?
If I take the networkView and movement update script off completely, the lighting is smooth. However, it doesn’t sync with the other clients (which is very important for this game).
Thanks!!
Movement Script:
using UnityEngine;
using System.Collections;
/*
©2014 Gamer To Game Developer.
This script is attached to an object and it
ensures that the object's position and rotation
are kept up to date across the network.
*/
public class S2_MovementSync : MonoBehaviour {
//Variables Start___________________________________
private Quaternion updatedRotation; //Used in capturing the object's last significant rotation.
private Transform myTransform; //A reference to the object's transform.
private Vector3 updatedPosition = new Vector3();
//Variables End_____________________________________
// Use this for initialization
void Awake ()
{
myTransform = transform;
updatedRotation = myTransform.rotation;
}
// Update is called once per frame
void Update ()
{
if(!networkView.isMine && Network.peerType != NetworkPeerType.Disconnected)
{
myTransform.rotation = Quaternion.Lerp(myTransform.rotation, updatedRotation, Time.deltaTime*10);
myTransform.position = Vector3.Lerp(myTransform.position, updatedPosition, Time.deltaTime*12);
}
}
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
Quaternion rot = new Quaternion();
Vector3 pos = new Vector3();
if(stream.isWriting)
{
pos = myTransform.position;
stream.Serialize(ref pos);
rot = myTransform.rotation;
stream.Serialize(ref rot);
}
else
{
stream.Serialize(ref pos);
updatedPosition = pos;
stream.Serialize(ref rot);
updatedRotation = rot;
}
}
}