Hello
I am doing my own FPS game and for multiplayer i am using Photon 2 (free). When i am testing the game with myself ( unity editor instance and build one on my PC) it seems like its running fine, i have ThinkPad labtop so anyway its running like 40-50 fps and about 30 ping.
my FPS formula
fpsTimer += Time.unscaledDeltaTime;
///fps
info.GetComponent<TextMeshProUGUI>().text = ((int)(1f / Time.unscaledDeltaTime)).ToString();
///ping
info2.GetComponent<TextMeshProUGUI>().text = PhotonNetwork.GetPing().ToString();
this is running in Update method in PlayerController and updating every 0.5 seconds.
As i said, when i am trying it on my labtop it runs fine, but when i test it with someone with gaming pc (fps about 700+ by code calculation) we have rly desync positioning of the player.
I am using common photon components , like object Player has PhotonView and also Photon Transform View , in the start of the game i do PhotonNetwork Instantiate players.
When the game starts , i see his movement very chopped and after some time he is appearing on random spots on the maps , its like moving extremnly fast or extremnly chopped, also even he is staying on the same place on his computer. I am using character controller for moving (instead of pushing rigidbody). My movement is executed during LateUpdate().
private void LateUpdate()
{
/*if(this.onElevator)
{
if(!inputController.PlayerHoverThisFrame() && !inputController.PlayerJumpedThisFrame())
{
moveVector.y = -0.5f;
}
}*/
if (isMultiPlayerInstance)
if (!this.PV.IsMine)
return;
if (!GamePaused)
{
if (!playerRelocated && isAlive)
{
controller.Move(moveVector * Time.deltaTime * playerSpeed);
if (controller.isGrounded)
{
if (playerSpeed < GlobalVariables.WALK_SPEED + 1f)
{
if (moveVector.x > 0.001f || moveVector.z > 0.00f || moveVector.x < -0.001f || moveVector.z < -0.00f)
{
if (!moveSound.isPlaying)
{
//walking
if (moveSound.clip != sprint1)
{
moveSound.clip = sprint1;
}
else
{
moveSound.clip = sprint2;
}
moveSound.Play();
}
}
}
else if (playerSpeed > GlobalVariables.WALK_SPEED + 1f)
{
if (!moveSound.isPlaying)
{
//walking
if (moveSound.clip != sprintBoostSound)
{
moveSound.clip = sprintBoostSound;
moveSound.Play();
}
}
}
}
}
else
playerRelocated = false;
rotXSensibility = GlobalVariables.MOUSE_ACCELERATION_X;
rotYSensibility = GlobalVariables.MOUSE_ACCELERATION_Y;
Vector2 rot = inputController.GetMouseDelta();
rotX -= rot.y * rotXSensibility * Time.deltaTime;
rotX = Mathf.Clamp(rotX, verticalDownLimit, verticalUpLimit);
rotY += rot.x * rotYSensibility * Time.deltaTime;
Quaternion rotation = Quaternion.Euler(rotX, rotY, 0);
cameraPointTransform.rotation = Quaternion.Euler(rotX, rotY, 0);
playerBodyTransform.rotation = Quaternion.Euler(0, rotY, 0);
/// shooting and melee
#region
if (this.isAlive)
{
if (inputController.PlyerMadeMeleeThisFrame() && !melee)
{
gunController.MeleeAtack();
}
melee = gunController.GetPerformingMelee();
if (inputController.PlayerFiredThisFrame() && !gunController.IsShooting() && !melee)
{
if (gunController.GetGunType() != GlobalVariables.GunType.Charger)
{
gunController.Shoot(cameraPointTransform.position, cameraPointTransform.forward, 1000f,Time.deltaTime);
RaycastHit hit = gunController.GetHit();
}
else
{
this.redGunCanShot = gunController.redGunChargingProcess(Time.deltaTime);
if (isMultiPlayerInstance)
this.redGunCanShot = gunController.RedGunCanShoot;
if (redGunCanShot)
{
gunController.Shoot(cameraPointTransform.position, cameraPointTransform.forward, 1000f, Time.deltaTime);
gunController.redGunChargingReset(true);
}
}
// Debug.Log(hit);
}
else
{
if (gunController.GetGunType() == GlobalVariables.GunType.LightningGun && !inputController.PlayerFiredThisFrame())
gunController.yellowGunReset();
redGunCanShot = false;
if (gunController.GetGunType() == GlobalVariables.GunType.Charger)
gunController.redGunChargingReset(false);
}
/* if (!playerRelocated)
controller.Move(moveVector * Time.deltaTime * playerSpeed);
else
playerRelocated = false;
*/
if (inputController.PlayerAltFireThisFrame() && !melee)
{
playerRelocated = gunController.AltShoot(gameObject.transform);
if (this.isMultiPlayerInstance)
playerRelocated = gunController.PlayerRelocated;
}
}
#endregion
}
}
Does anybody has any idea why this could be happening? My first guess , maybe change my LateUpdate to FixedUpdate , or maybe i am doing tottaly wrong something.
Thank you for help guys