To those that know unity far more than me :)
I have a weird issue in a networked fps... Nothing particularly fancy is happening. I have a gunManager with its own NetworkView (state sync off) attached to a node called 'Weapons' which is some descendant in my player object hiearchy: which also has NetworkView w/ synchronized compressed data.
The GunManager is straight foward, it checks to see if the player has fired then RPC's when the shot is made with RPCMode.Others so that they can display the bullet/rocket/etc....
if (!LocalPlayer)
{ return; }
if (Input.GetButtonDown("Fire1"))
{
//... gets info on camera
float distance = SelectedGun.Range;
bool hit = Physics.Raycast(transform.position, worldDirection, out info, distance);
if (hit && info.collider.gameObject.tag == "Player")
{
//calculates local damage, updates local score, etc...
}
networkView.RPC("FiredOneShot", RPCMode.Others, transform.position, worldDirection, info.normal, info.distance, SelectedGun.GunID);
FiredOneShot(transform.position, worldDirection, info.normal, info.distance, SelectedGun.GunID);
//...
}
[RPC]
public void FiredOneShot(Vector3 origin, Vector3 direction, Vector3 normal, float distance, int gunID)
{
Debug.Log("Player Fired: ");
GunData.GunType type = GameData.Instance.GunData[gunID].Type;
if (type == GunData.GunType.Rail)
{
if (distance < 5)
{
distance = 300;
}
Quaternion q = Quaternion.FromToRotation(new Vector3(0, 1, 0), direction);
Transform t = (Transform)Instantiate(LazerPrefab, origin, q);
t.localScale = new Vector3(0.2f, distance, 0.2f);
}
}
Given this, my lazerprefab is just a cylinder, but for some reason anytime a player who isn't the server 'fires', they have a local chug. But the server does not experience this. In fact, if the server fires alot everyone in the game chugs. The 'chug' is like a 5-10 FRAME lockup(drop) which is very disorienting. I am pretty sure this is the standard way of architecting networking for a gunshot. At first I thought it was the local Instantiate in the Rpc: FiredOneShot, but if I completely comment this function out I still notice the chugging. Has anyone else come across this or have suggestions to try out ?
Appreciate the advice, ~J