I'm making a billiard game and I wanna implement multiplayer in it. Since updating the movement in every frame is inefficient and laggy, I thought I could remake the events in game happen in all clients but for some reason they differ from one another.
The direction that the ball launches is correct but it starts to differ for different users when it collides with other balls(if it collides only with the wall it's fine). Technically this shouldn't happen IMO.
This is the code I use to add force to the player ball:
I use this to launch the player ball
photonView.RPC("FireBall", PhotonTargets.All, storedDirection, power);
This is the function that adds the force to the player ball.
[PunRPC]
public void FireBall(Vector3 stordDir , float poww)
{
rigidbody.AddForce(stordDir.normalized * poww, ForceMode.Impulse);
}
I use this function to get the desired direction of the player.
public void UpdateStickPosition()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
{
if (Input.GetKeyDown(KeyCode.Mouse0)
{
storedDirection = hit.point - transform.position;
}
}
}
I appreciate all help given, don't hesitate to ask me any questions.