I am currently running a authoritative server using uLink’s middle ware. I am having issues with keeping the client and the server in sync when the player is shooting. Currently the player sends a RPC to the server, the server and client both create bullets. My issues is sometimes the server fires +/- one bullet from what the client does. Any suggestions on how to keep this more in sync. The code I am using is below.
This script is called every time we fire want to fire.
public void machineGunFire (){
if (machinegunbulletsLeft == 0){
return;
}
if (Time.time - mgfireRate > nextFireTime){
nextFireTime = Time.time - Time.deltaTime;
}
while( nextFireTime < Time.time && machinegunbulletsLeft != 0){
AmountofBulletsFired++;
AmountofBulletsFiredForSpread++;
StartCoroutine(machineGunOneShot());
nextFireTime += mgfireRate;
}
}
On the server.
[RPC]
public void areWeFiringOurGun(bool varible, uLink.NetworkMessageInfo info){
RPCSender = info.sender;
weAreFiring = varible;
TimeFireMessageWasSent = info.timestampInMillis;
if(weAreFiring){
machineGunFire();
}
}
void machineGunFire (){
if (machinegunbulletsLeft == 0){
//canWeFire = false;
return;
}
if (Time.time - mgfireRate > nextFireTime){
nextFireTime = Time.time - Time.deltaTime;
}
while( nextFireTime < Time.time && machinegunbulletsLeft != 0){
machineGunOneShot();
AmountofBulletsFiredForSpread++;
nextFireTime += mgfireRate;
}
}