- Home /
Photon - How to sync ball in soccer game
I'm making multiplayer soccer game but I'm having problem with sync I guess. The ball take force from only master. When the other players shoot the ball, it doesn't move because of the lag. I've tried the owner transfer with ontriggerenter2d and it makes more good but when the owner transfer happens, new owner pull the ball to itself. So its not a proper way.
Also I used OnPhotonSerializeView but its not helped to me anyway. How do I fix this?
i dont think you have to user OnPhotonSerializeView,attach a networked position component and rotation component this will sync the balls position ,when master adds force the balls position will be synced across all clients .hope this helps
Answer by BRW_arjan · Oct 04, 2019 at 09:47 AM
I think you should change the owner as soon as another player kicks the ball. After the ownership transfer you can apply the kicking force to the ball and it should sync to the other players.
It make sense partially but what if player wants to push the ball? Then the same problem occurs and player can't move the ball with pushing.
Pushing can, just like kicking inflict small forces on the ball. As long as you use forces and no direct transform setting it should work fine. Are you also syncing the rigidbody or just the transform?
I've synced both. Rigidbody and transform. No only owner can moves the ball. Either push and kick. If you are not owner, server doesn't take parameter from your tries.
Answer by hamza37 · Jul 12, 2021 at 03:15 AM
private void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "Player") { this.photonView.TransferOwnership(col.gameObject.GetComponent().Owner); } }